ARTEMIS-2997 NPE with JMS queue/topic toString()

This commit is contained in:
Justin Bertram 2020-11-17 08:16:55 -06:00 committed by Clebert Suconic
parent 05b9c3cb6d
commit 2c0b192e81
2 changed files with 23 additions and 1 deletions

View File

@ -464,7 +464,7 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se
// Public --------------------------------------------------------
public String getAddress() {
return simpleAddress.toString();
return simpleAddress != null ? simpleAddress.toString() : null;
}
public SimpleString getSimpleAddress() {

View File

@ -21,6 +21,8 @@ import javax.jms.Queue;
import javax.jms.Topic;
import org.apache.activemq.artemis.jms.client.ActiveMQDestination;
import org.apache.activemq.artemis.jms.client.ActiveMQQueue;
import org.apache.activemq.artemis.jms.client.ActiveMQTopic;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.apache.activemq.artemis.utils.RandomUtil;
import org.junit.Assert;
@ -81,6 +83,26 @@ public class ActiveMQDestinationTest extends ActiveMQTestBase {
Assert.assertTrue(destination instanceof Destination);
}
@Test
public void testQueueToStringNPE() {
ActiveMQDestination destination = new ActiveMQQueue();
try {
System.out.println("Destination: " + destination.toString());
} catch (NullPointerException npe) {
Assert.fail("Caught NPE!");
}
}
@Test
public void testTopicToStringNPE() {
ActiveMQDestination destination = new ActiveMQTopic();
try {
System.out.println("Destination: " + destination.toString());
} catch (NullPointerException npe) {
Assert.fail("Caught NPE!");
}
}
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------