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**
This commit is contained in:
Artem Bilan
2018-03-28 14:42:56 -04:00
committed by Gary Russell
parent b66d54c3b8
commit 450d27f697
2 changed files with 20 additions and 3 deletions

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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)) { else if (!this.contentType.equals(other.contentType)) {
return false; 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; return false;
} }
if (this.deliveryMode != other.deliveryMode) { if (this.deliveryMode != other.deliveryMode) {
return false; return false;
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 Dave Syer
* @author Artem Yakshin * @author Artem Yakshin
* @author Artem Bilan
* *
*/ */
public class MessagePropertiesTests { public class MessagePropertiesTests {
@Test @Test
public void testReplyTo() throws Exception { public void testReplyTo() throws Exception {
MessageProperties properties = new MessageProperties(); MessageProperties properties = new MessageProperties();
@@ -61,4 +64,11 @@ public class MessagePropertiesTests {
assertTrue(properties.isContentLengthSet()); assertTrue(properties.isContentLengthSet());
} }
@Test
public void tesNoNullPointerInEquals() {
MessageProperties mp = new MessageProperties();
MessageProperties mp2 = new MessageProperties();
assertTrue(mp.equals(mp2));
}
} }