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

Fixing NPE in AbstractNamedValueMethodArgumentResolver #23882

Closed
wants to merge 1 commit into from
Closed

Fixing NPE in AbstractNamedValueMethodArgumentResolver #23882

wants to merge 1 commit into from

Conversation

dekelpilli
Copy link
Contributor

@dekelpilli dekelpilli commented Oct 29, 2019

Upgrading one of our apps to Spring Boot 2.2.0.RELEASE (with Spring 5.2.0.RELEASE) is blocked by a null pointer exception in AbstractNamedValueMethodArgumentResolver that occurs whenever we are trying to receive a message via an SqsListener.

My approach is to undo 5b3b0b1#diff-ba4bc09499d8cbf059d24ea9c6062b9cL82

@pivotal-issuemaster
Copy link

@dekelpilli Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@dekelpilli Thank you for signing the Contributor License Agreement!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 29, 2019
@rstoyanchev rstoyanchev added in: messaging Issues in messaging modules (jms, messaging) type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 31, 2019
@rstoyanchev rstoyanchev added this to the 5.2.1 milestone Oct 31, 2019
@rstoyanchev rstoyanchev self-assigned this Oct 31, 2019
@rstoyanchev
Copy link
Contributor

@dekelpilli, I can make this more lenient again to avoid a NPE but it does mean that some code somewhere is creating the argument resolver by passing null as the ConversionService. Can you provide a stack trace or help me to understand which project is creating the argument resolver?

@dekelpilli
Copy link
Contributor Author

@rstoyanchev Sure, I'll try to do that at work tomorrow. The problem is that the stacktrace is from when the exception is thrown, not when the resolver is built. I'll try to run it locally with a breakpoint and provide that as well.

@rstoyanchev
Copy link
Contributor

Right, I would only use the stacktrace as a clue. If you can point me to the code that's creating the resolver that would be quite sufficient.

pull bot pushed a commit to scope-demo/spring-framework that referenced this pull request Oct 31, 2019
pull bot pushed a commit to scope-demo/spring-framework that referenced this pull request Oct 31, 2019
@dekelpilli
Copy link
Contributor Author

Creation stacktrace (this is from a test running locally, but the issue first appeared in a live dev server):

at org.springframework.messaging.handler.annotation.support.AbstractNamedValueMethodArgumentResolver.<init>(AbstractNamedValueMethodArgumentResolver.java:78)
	at org.springframework.messaging.handler.annotation.support.HeaderMethodArgumentResolver.<init>(HeaderMethodArgumentResolver.java:54)
	at org.springframework.cloud.aws.messaging.listener.QueueMessageHandler.initArgumentResolvers(QueueMessageHandler.java:86)
	at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.afterPropertiesSet(AbstractMethodMessageHandler.java:236)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1862)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:212)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.resolveBeanReference(ConfigurationClassEnhancer.java:393)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:366)
	at org.springframework.cloud.aws.messaging.config.annotation.SqsConfiguration$$EnhancerBySpringCGLIB$$5b2bea87.queueMessageHandler(<generated>)
	at org.springframework.cloud.aws.messaging.config.annotation.SqsConfiguration.simpleMessageListenerContainer(SqsConfiguration.java:70)
	at org.springframework.cloud.aws.messaging.config.annotation.SqsConfiguration$$EnhancerBySpringCGLIB$$5b2bea87.CGLIB$simpleMessageListenerContainer$0(<generated>)
	at org.springframework.cloud.aws.messaging.config.annotation.SqsConfiguration$$EnhancerBySpringCGLIB$$5b2bea87$$FastClassBySpringCGLIB$$36664d62.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)
	at org.springframework.cloud.aws.messaging.config.annotation.SqsConfiguration$$EnhancerBySpringCGLIB$$5b2bea87.simpleMessageListenerContainer(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:640)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:625)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
	at [our public static void main SpringApplication.run() call]

Exception stacktrace:

Unhandled exception from message handler method
java.lang.NullPointerException: null
at org.springframework.messaging.handler.annotation.support.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:111)
at org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:117)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:148)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:116)
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMatch(AbstractMethodMessageHandler.java:565)
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessageInternal(AbstractMethodMessageHandler.java:520)
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessage(AbstractMethodMessageHandler.java:454)
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer.executeMessage(SimpleMessageListenerContainer.java:205)
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$MessageExecutor.run(SimpleMessageListenerContainer.java:342)
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$SignalExecutingRunnable.run(SimpleMessageListenerContainer.java:397)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Nov 1, 2019

Thanks, it's right here where the header resolver is created.

I've processed the change to fall back on a default ConversionService as it did before but I have removed the @Nullable annotations to continue to indicate it should be passed in. Ideally QueueMessageHandler should have a configurable ConversionService like this here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging Issues in messaging modules (jms, messaging) type: regression A bug that is also a regression
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants