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

NPE in the RedisQueueOutboundChannelAdapter caused by the misconfiguration for the RedisMessageChannelBinder #166

Closed
artembilan opened this issue Oct 28, 2015 · 1 comment

Comments

@artembilan
Copy link
Contributor

2015-10-28 11:45:43,630 ERROR inbound.retry.0-redis:queue-inbound-channel-adapter1 o.s.c.s.b.r.RedisMessageChannelBinder$1:286 - Failed to deliver message
org.springframework.messaging.MessageHandlingException: error occurred in message handler [org.springframework.integration.redis.outbound.RedisQueueOutboundChannelAdapter@5f977c77]; nested exception is java.lang.IllegalArgumentException: EvaluationContext must not be null
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:139) ~[spring-integration-core-4.2.1.RELEASE.jar:na]
    at org.springframework.cloud.stream.binder.redis.RedisMessageChannelBinder$1$2.recover(RedisMessageChannelBinder.java:277) ~[classes/:na]
    at org.springframework.cloud.stream.binder.redis.RedisMessageChannelBinder$1$2.recover(RedisMessageChannelBinder.java:267) ~[classes/:na]
    at org.springframework.retry.support.RetryTemplate.handleRetryExhausted(RetryTemplate.java:458) ~[spring-retry-1.1.2.RELEASE.jar:na]
    at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:320) ~[spring-retry-1.1.2.RELEASE.jar:na]
    at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:168) ~[spring-retry-1.1.2.RELEASE.jar:na]
    at org.springframework.cloud.stream.binder.redis.RedisMessageChannelBinder$1.doSend(RedisMessageChannelBinder.java:260) ~[classes/:na]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:442) [spring-integration-core-4.2.1.RELEASE.jar:na]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:392) [spring-integration-core-4.2.1.RELEASE.jar:na]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115) [spring-messaging-4.2.3.BUILD-20151027.143026-12.jar:4.2.3.BUILD-SNAPSHOT]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45) [spring-messaging-4.2.3.BUILD-20151027.143026-12.jar:4.2.3.BUILD-SNAPSHOT]
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105) [spring-messaging-4.2.3.BUILD-20151027.143026-12.jar:4.2.3.BUILD-SNAPSHOT]
    at org.springframework.integration.endpoint.MessageProducerSupport.sendMessage(MessageProducerSupport.java:105) [spring-integration-core-4.2.1.RELEASE.jar:na]
    at org.springframework.integration.redis.inbound.RedisQueueMessageDrivenEndpoint.popMessageAndSend(RedisQueueMessageDrivenEndpoint.java:224) [spring-integration-redis-4.2.1.RELEASE.jar:na]
    at org.springframework.integration.redis.inbound.RedisQueueMessageDrivenEndpoint.access$300(RedisQueueMessageDrivenEndpoint.java:54) [spring-integration-redis-4.2.1.RELEASE.jar:na]
    at org.springframework.integration.redis.inbound.RedisQueueMessageDrivenEndpoint$ListenerTask.run(RedisQueueMessageDrivenEndpoint.java:323) [spring-integration-redis-4.2.1.RELEASE.jar:na]
    at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:55) [spring-integration-core-4.2.1.RELEASE.jar:na]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_51]
Caused by: java.lang.IllegalArgumentException: EvaluationContext must not be null
    at org.springframework.util.Assert.notNull(Assert.java:115) ~[spring-core-4.2.3.BUILD-20151027.143026-12.jar:4.2.3.BUILD-SNAPSHOT]
    at org.springframework.expression.spel.ExpressionState.<init>(ExpressionState.java:85) ~[spring-expression-4.2.3.BUILD-20151027.143026-12.jar:4.2.3.BUILD-SNAPSHOT]
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:329) ~[spring-expression-4.2.3.BUILD-20151027.143026-12.jar:4.2.3.BUILD-SNAPSHOT]
    at org.springframework.integration.redis.outbound.RedisQueueOutboundChannelAdapter.handleMessageInternal(RedisQueueOutboundChannelAdapter.java:115) ~[spring-integration-redis-4.2.1.RELEASE.jar:na]
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127) ~[spring-integration-core-4.2.1.RELEASE.jar:na]
    ... 17 common frames omitted

That's just because:

@Override
public void afterPropertiesSet() throws Exception {
    Assert.notNull(this.applicationContext, "The 'applicationContext' property cannot be null");
    onInit();
    if (this.evaluationContext == null) {
        this.evaluationContext = IntegrationContextUtils.getEvaluationContext(getBeanFactory());
    }
}

in the MessageChannelBinderSupport, but the RedisMessageChannelBinder has this code:

protected void onInit() {
    this.errorAdapter.setIntegrationEvaluationContext(this.evaluationContext);
}

So, we populate null to the RedisQueueOutboundChannelAdapter in case of normal application initialization.

@artembilan
Copy link
Contributor Author

The PR will be soon, BTW...

artembilan added a commit to artembilan/spring-cloud-stream that referenced this issue Oct 28, 2015
Fixes spring-cloudGH-166 (spring-cloud#166)

Since `onInit()` in the `MessageChannelBinderSupport` was called before the `evaluationContext` population,
the `RedisMessageChannelBinder#errorAdapter` caused `NPE` for its `evaluationContext`.

* Change the initialization order
* Use `ExpressionUtils` to populate `evaluationContext` - creates `StandardEvaluationContext` if there is no one in the `applicationContext`
* Add more initializations for the `RedisMessageChannelBinder#errorAdapter`
* Remove explicit `evaluationContext` population from the `AbstractTestBinder` to rely on the fix for this ticket
* Some other simple polishing
sobychacko pushed a commit to sobychacko/spring-cloud-stream that referenced this issue Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant