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 -----------------------------------------------------