Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-1455

HateoasPageableHandlerMethodArgumentResolver doesn't handle Pageable.unpaged() correctly

    XMLWordPrintable

    Details

      Description

      I noticed that since spring-data-commons release 2.0.12 (if not the earlier 2.x versions), using the method

      org.springframework.data.web.PagedResourcesAssembler#toResource()

      eventually culminates in calling 

      org.springframework.data.web.HateoasPageableHandlerMethodArgumentResolver#enhance()

      , which throws an UnsupportedOperationException. I noticed this while upgrading our project from Spring Boot 1.4 (with spring-data-commons-1.12.2) to Spring Boot 2.0 (with spring-data-commons-2.0.12).

      I suspect the reason behind this is that in spring-data-commons-2.x (as opposed to 1.x), the method addPaginationLinks() in class PagedResourcesAssembler was modified as follows:

      spring-data-commons-2.0.12 (inside method addPaginationLinks):

      Link selfLink = link.map(it -> it.withSelfRel())//
       .orElseGet(() -> createLink(base, page.getPageable(), Link.REL_SELF));

      spring-data-commons-1.12.2 (inside method addPaginationLinks):

      resources.add(createLink(base, null, Link.REL_SELF));

      As you can see, the method createLink is now being passed a page.getPageable(), as opposed to null, which down the line gets passed to HateoasPageableHandlerMethodArgumentResolver#enhance(), which throws an UnsupportedOperationException when pageable.getPageNumber(); is called inside it. Previously, a null was being passed to this enhance() method, which resulted in an early return due to this if condition:

       

      if (!(value instanceof Pageable)) {
       return;
      } 
      

      I am not very familiar with the spring-data-commons library, but if someone could shed some light on this, I would be grateful. Thanks.

      FYI, here are all the versions of the different libraries I am using:

      spring-boot: 2.0.7

      spring-data-commons: 2.0.12.RELEASE

      spring-boot-starter-data-jpa: 2.0.7.RELEASE

      spring-boot-starter-data-rest: 2.0.7.RELEASE

      spring-data-rest-core: 3.0.12.RELEASE

      spring-data-jpa: 2.0.12.RELEASE

      spring-hateoas:0.25.0.RELEASE

      spring: 5.0.11.RELEASE

        Attachments

          Activity

            People

            Assignee:
            olivergierke Oliver Drotbohm
            Reporter:
            lebowski Rishikesh Pandey
            Last updater:
            Mark Paluch
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: