From 8f1a1c1777c983e5ef56ef945eea32cfb082b242 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 22 Feb 2019 11:02:16 -0500 Subject: [PATCH] Fix possible NPE when generate correlationData **Cherry-pick to 4.3.x** Related to https://github.com/spring-projects/spring-integration/pull/2761 --- .../AbstractAmqpOutboundEndpoint.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java index bd145d5d4c..3d540ab39f 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/outbound/AbstractAmqpOutboundEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2018 the original author or authors. + * Copyright 2016-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.integration.amqp.outbound; import java.util.HashMap; import java.util.Map; +import java.util.UUID; import org.springframework.amqp.core.MessageDeliveryMode; import org.springframework.amqp.rabbit.connection.Connection; @@ -54,6 +55,8 @@ import org.springframework.util.StringUtils; public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducingMessageHandler implements Lifecycle { + private static final UUID NO_ID = new UUID(0L, 0L); + private String exchangeName; private String routingKey; @@ -472,8 +475,18 @@ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducin protected CorrelationData generateCorrelationData(Message requestMessage) { CorrelationData correlationData = null; if (this.correlationDataGenerator != null) { - correlationData = new CorrelationDataWrapper(requestMessage.getHeaders().getId().toString(), - this.correlationDataGenerator.processMessage(requestMessage), requestMessage); + UUID messageId = requestMessage.getHeaders().getId(); + if (messageId == null) { + messageId = NO_ID; + } + Object userData = this.correlationDataGenerator.processMessage(requestMessage); + if (userData != null) { + correlationData = new CorrelationDataWrapper(messageId.toString(), userData, requestMessage); + } + else { + this.logger.debug("'confirmCorrelationExpression' resolved to 'null'; " + + "no publisher confirm will be sent to the ack or nack channel"); + } } return correlationData; }