From 2c0b192e8156afe8272fe7723759d935b3ced6d1 Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Tue, 17 Nov 2020 08:16:55 -0600 Subject: [PATCH] ARTEMIS-2997 NPE with JMS queue/topic toString() --- .../jms/client/ActiveMQDestination.java | 2 +- .../unit/jms/ActiveMQDestinationTest.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java index 10a39d78a3..fbc542dc06 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java @@ -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() { diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/ActiveMQDestinationTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/ActiveMQDestinationTest.java index 0e4ca36246..dd4c41b158 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/ActiveMQDestinationTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/jms/ActiveMQDestinationTest.java @@ -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 -----------------------------------------------------