From 450d27f697416b2f5e25a5726da7b148ca7f4a54 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 28 Mar 2018 14:42:56 -0400 Subject: [PATCH] GH-730: Fix NPE in the MessageProperties Fixes https://github.com/spring-projects/spring-amqp/issues/730 **Cherry-pick to 2.0.x and 1.7.x** --- .../springframework/amqp/core/MessageProperties.java | 11 +++++++++-- .../amqp/core/MessagePropertiesTests.java | 12 +++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) 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 44eb3898..aacde988 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -590,9 +590,16 @@ public class MessageProperties implements Serializable { else if (!this.contentType.equals(other.contentType)) { return false; } - if (!this.correlationId.equals(other.correlationId)) { + + if (this.correlationId == null) { + if (other.correlationId != null) { + return false; + } + } + else if (!this.correlationId.equals(other.correlationId)) { 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 e1c8c948..eff9cf29 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -26,10 +26,13 @@ import org.junit.Test; /** * @author Dave Syer * @author Artem Yakshin + * @author Artem Bilan * */ public class MessagePropertiesTests { + + @Test public void testReplyTo() throws Exception { MessageProperties properties = new MessageProperties(); @@ -61,4 +64,11 @@ public class MessagePropertiesTests { assertTrue(properties.isContentLengthSet()); } + @Test + public void tesNoNullPointerInEquals() { + MessageProperties mp = new MessageProperties(); + MessageProperties mp2 = new MessageProperties(); + assertTrue(mp.equals(mp2)); + } + }