Skip to content

Commit 442b3d9

Browse files
committed
Fix possible NPE when generate correlationData
**Cherry-pick to 4.3.x** Related to #2761 # Conflicts: # spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java
1 parent c3c3f81 commit 442b3d9

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 the original author or authors.
2+
* Copyright 2016-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.util.HashMap;
2020
import java.util.Map;
21+
import java.util.UUID;
2122

2223
import org.springframework.amqp.core.MessageDeliveryMode;
2324
import org.springframework.amqp.rabbit.connection.Connection;
@@ -51,6 +52,8 @@
5152
public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducingMessageHandler
5253
implements Lifecycle {
5354

55+
private static final UUID NO_ID = new UUID(0L, 0L);
56+
5457
private String exchangeName;
5558

5659
private String routingKey;
@@ -429,8 +432,18 @@ public boolean isRunning() {
429432
protected CorrelationData generateCorrelationData(Message<?> requestMessage) {
430433
CorrelationData correlationData = null;
431434
if (this.correlationDataGenerator != null) {
432-
correlationData = new CorrelationDataWrapper(requestMessage.getHeaders().getId().toString(),
433-
this.correlationDataGenerator.processMessage(requestMessage), requestMessage);
435+
UUID messageId = requestMessage.getHeaders().getId();
436+
if (messageId == null) {
437+
messageId = NO_ID;
438+
}
439+
Object userData = this.correlationDataGenerator.processMessage(requestMessage);
440+
if (userData != null) {
441+
correlationData = new CorrelationDataWrapper(messageId.toString(), userData, requestMessage);
442+
}
443+
else {
444+
this.logger.debug("'confirmCorrelationExpression' resolved to 'null'; "
445+
+ "no publisher confirm will be sent to the ack or nack channel");
446+
}
434447
}
435448
return correlationData;
436449
}

0 commit comments

Comments
 (0)