Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HateoasPageableHandlerMethodArgumentResolver doesn't handle Pageable.unpaged() correctly [DATACMNS-1455]

Closed
spring-projects-issues opened this issue Dec 20, 2018 · 7 comments
Assignees
Labels
type: bug

Comments

@spring-projects-issues
Copy link

spring-projects-issues commented Dec 20, 2018

Rishikesh Pandey opened DATACMNS-1455 and commented

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


Affects: 2.2 M1 (Moore), 2.0.12 (Kay SR12), 2.1.3 (Lovelace SR3)

Referenced from: commits c209737, 3623e18, 566e6a3

Backported to: 2.1.4 (Lovelace SR4), 2.0.13 (Kay SR13)

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Dec 20, 2018

Rishikesh Pandey commented

Added versions of the libraries that I am using

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Dec 21, 2018

Oliver Drotbohm commented

That should be fixed, feel free to give the snapshots a try

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Dec 21, 2018

Rishikesh Pandey commented

I am trying the 2.2.0.BUILD-SNAPSHOT version. With this I get the following error while starting up the project:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'roleRepository': Invocation of init method failed; nested exception is java.lang.IllegalStateException: You have defined query method in the repository but you don't have any query lookup strategy defined. The infrastructure apparently does not support query methods!Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'roleRepository': Invocation of init method failed; nested exception is java.lang.IllegalStateException: You have defined query method in the repository but you don't have any query lookup strategy defined. The infrastructure apparently does not support query methods! at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1694) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:581) ... 96 moreCaused by: java.lang.IllegalStateException: You have defined query method in the repository but you don't have any query lookup strategy defined. The infrastructure apparently does not support query methods! at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:545) at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:324) at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297) at org.springframework.data.util.Lazy.getNullable(Lazy.java:211) at org.springframework.data.util.Lazy.get(Lazy.java:94) at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300) at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:102) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1753) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1690) ... 106 more

Is the snapshot version compatible with Spring Boot 2.0.7? Going by the name, I would assume it only works for Spring Boot 2.2.

 

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Dec 21, 2018

Rishikesh Pandey commented

Actually, nevermind, I was able to build the project using 2.0.13.BUILD-SNAPSHOT

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Dec 21, 2018

Rishikesh Pandey commented

Confirmed that this bug is removed in 2.0.13.BUILD_SNAPSHOT. Thanks for your help!

Is there a release date scheduled for 2.0.13.RELEASE?

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Jan 4, 2019

Rishikesh Pandey commented

Oliver Drotbohm, hi again, is a stable release version for 2.0.13 planned to be released sometime? We are stuck on the snapshot version currently because of this issue and would like to move on to a stable release if possible.

Thanks,
Rishi

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Jan 7, 2019

Oliver Drotbohm commented

The Spring releases calendar can be found here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug
Projects
None yet
Development

No branches or pull requests

2 participants