From d6a5a7555b06a9ed3abd23b192943c5b89b0dbe2 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Wed, 28 Mar 2018 14:53:08 -0400 Subject: [PATCH] GH-730: Fix NPE in the MessageProperties Fixes https://github.com/spring-projects/spring-amqp/issues/730 --- .../org/springframework/amqp/core/MessageProperties.java | 8 ++++++++ .../springframework/amqp/core/MessagePropertiesTests.java | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/spring-amqp/src/main/java/org/springframework/amqp/core/MessageProperties.java b/spring-amqp/src/main/java/org/springframework/amqp/core/MessageProperties.java index fc55bdc6..90ceae87 100644 --- a/spring-amqp/src/main/java/org/springframework/amqp/core/MessageProperties.java +++ b/spring-amqp/src/main/java/org/springframework/amqp/core/MessageProperties.java @@ -568,6 +568,14 @@ public class MessageProperties implements Serializable { if (!Arrays.equals(this.correlationId, other.correlationId)) { return false; } + if (this.correlationIdString == null) { + if (other.correlationIdString != null) { + return false; + } + } + else if (!this.correlationIdString.equals(other.correlationIdString)) { + return false; + } if (this.deliveryMode != other.deliveryMode) { return false; } diff --git a/spring-amqp/src/test/java/org/springframework/amqp/core/MessagePropertiesTests.java b/spring-amqp/src/test/java/org/springframework/amqp/core/MessagePropertiesTests.java index 0e0a6e80..ac6ee2af 100644 --- a/spring-amqp/src/test/java/org/springframework/amqp/core/MessagePropertiesTests.java +++ b/spring-amqp/src/test/java/org/springframework/amqp/core/MessagePropertiesTests.java @@ -17,6 +17,7 @@ package org.springframework.amqp.core; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -41,4 +42,11 @@ public class MessagePropertiesTests { assertEquals(null, properties.getReplyToAddress()); } + @Test + public void tesNoNullPointerInEquals() { + MessageProperties mp = new MessageProperties(); + MessageProperties mp2 = new MessageProperties(); + assertTrue(mp.equals(mp2)); + } + }