Skip to content

Commit 450d27f

Browse files
artembilangaryrussell
authored andcommitted
GH-730: Fix NPE in the MessageProperties
Fixes #730 **Cherry-pick to 2.0.x and 1.7.x**
1 parent b66d54c commit 450d27f

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

spring-amqp/src/main/java/org/springframework/amqp/core/MessageProperties.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -590,9 +590,16 @@ else if (!this.contentEncoding.equals(other.contentEncoding)) {
590590
else if (!this.contentType.equals(other.contentType)) {
591591
return false;
592592
}
593-
if (!this.correlationId.equals(other.correlationId)) {
593+
594+
if (this.correlationId == null) {
595+
if (other.correlationId != null) {
596+
return false;
597+
}
598+
}
599+
else if (!this.correlationId.equals(other.correlationId)) {
594600
return false;
595601
}
602+
596603
if (this.deliveryMode != other.deliveryMode) {
597604
return false;
598605
}

spring-amqp/src/test/java/org/springframework/amqp/core/MessagePropertiesTests.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -26,10 +26,13 @@
2626
/**
2727
* @author Dave Syer
2828
* @author Artem Yakshin
29+
* @author Artem Bilan
2930
*
3031
*/
3132
public class MessagePropertiesTests {
3233

34+
35+
3336
@Test
3437
public void testReplyTo() throws Exception {
3538
MessageProperties properties = new MessageProperties();
@@ -61,4 +64,11 @@ public void testContentLengthSet() {
6164
assertTrue(properties.isContentLengthSet());
6265
}
6366

67+
@Test
68+
public void tesNoNullPointerInEquals() {
69+
MessageProperties mp = new MessageProperties();
70+
MessageProperties mp2 = new MessageProperties();
71+
assertTrue(mp.equals(mp2));
72+
}
73+
6474
}

0 commit comments

Comments
 (0)