Skip to content

java.lang.NullPointerException thrown if doGetValue returns "null" #3113

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

Closed
msalado opened this issue Nov 21, 2019 · 3 comments
Closed

java.lang.NullPointerException thrown if doGetValue returns "null" #3113

msalado opened this issue Nov 21, 2019 · 3 comments

Comments

@msalado
Copy link

msalado commented Nov 21, 2019

@msalado
Copy link
Author

msalado commented Nov 21, 2019

Hi, we have a production code that worked fined for some years now, until we recently upgraded to spring-integration-jdbc module to the latest version available 5.2.1.

We catch this issue, which I've replicated in a Unit test. If any of the following properties in the payload is null the flow will fail

this is a simplified snippet of the configuration we have

	<bean id="updateStpSpeiSentRequestSource" class="org.springframework.integration.jdbc.ExpressionEvaluatingSqlParameterSourceFactory">
		<property name="parameterExpressions">
			<map>
				<entry key="id"    			value="payload.id"/>
				<entry key="stpId"  		value="payload.idStp"/>
				<entry key="signature"      value="payload.signature"/>
			</map>
		</property>
	</bean>

So, I've tracked down and debugged locally to the line 230 of ExpressionEvaluatingSqlParameterSourceFactory

java.lang.NullPointerException
	at org.springframework.integration.jdbc.ExpressionEvaluatingSqlParameterSourceFactory$ExpressionEvaluatingSqlParameterSource.hasValue(ExpressionEvaluatingSqlParameterSourceFactory.java:230)
	at org.springframework.jdbc.core.namedparam.NamedParameterUtils.substituteNamedParameters(NamedParameterUtils.java:281)
	at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.getPreparedStatementCreatorFactory(NamedParameterJdbcTemplate.java:454)
	at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.getPreparedStatementCreator(NamedParameterJdbcTemplate.java:414)
	at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:341)
	at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.update(NamedParameterJdbcTemplate.java:333)
	at org.springframework.integration.jdbc.JdbcMessageHandler.executeUpdateQuery(JdbcMessageHandler.java:213)
	at org.springframework.integration.jdbc.JdbcOutboundGateway.handleRequestMessage(JdbcOutboundGateway.java:168)
	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:127)
	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:177)
	at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:115)
	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:133)
	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:106)
	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73)
	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:461)
	at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:187)
	at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:233)
	at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:47)
	at org.springframework.messaging.core.AbstractMessagingTemplate.sendAndReceive(AbstractMessagingTemplate.java:46)
	at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:97)
	at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:38)
	at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:96)
	at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:86)
	at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:495)
	at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceive(MessagingGatewaySupport.java:469)
	at org.springframework.integration.gateway.GatewayProxyFactoryBean.sendOrSendAndReceive(GatewayProxyFactoryBean.java:564)
	at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:489)
	at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:464)
	at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:453)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
	at com.sun.proxy.$Proxy49.update(Unknown Source)

@artembilan
Copy link
Member

Wow! Great catch!
Any chances to see a fix from you?
I gladly review it and merge in the morning.

Thank you!

@msalado
Copy link
Author

msalado commented Nov 21, 2019

Hi Artem,

Actually, the former code until 5.1.9.RELEASE was

if (value == ERROR) { return false; }

And then changed to

if (value.equals(ERROR)) { return false; }

Therefore, it seems a simple null check safeguard would be enough

if (value != null && value.equals(ERROR)) { return false; }

Regards,

@garyrussell garyrussell self-assigned this Nov 21, 2019
artembilan added a commit that referenced this issue Nov 21, 2019
Related to #3113

Also clean up code style in the `ExpressionEvaluatingSqlParameterSourceFactory`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants