From d4041b5a72edae68fd70c43ba9a53023b5ec567d Mon Sep 17 00:00:00 2001 From: "Christopher L. Shannon (cshannon)" Date: Wed, 28 Feb 2018 14:01:51 -0500 Subject: [PATCH] ARTEMIS-1713 - Fix NPE inside OpenWireConnection fix NPE inside getClientId() in OpenWireConnection --- .../protocol/openwire/OpenWireConnection.java | 4 ++-- .../plugin/OpenwirePluginTest.java | 20 +++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java index 99733ec305..803ed22f3f 100644 --- a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java +++ b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java @@ -193,7 +193,7 @@ public class OpenWireConnection extends AbstractRemotingConnection implements Se private final Set knownDestinations = new ConcurrentHashSet<>(); - private AtomicBoolean disableTtl = new AtomicBoolean(false); + private final AtomicBoolean disableTtl = new AtomicBoolean(false); public OpenWireConnection(Connection connection, ActiveMQServer server, @@ -1676,7 +1676,7 @@ public class OpenWireConnection extends AbstractRemotingConnection implements Se @Override public String getClientID() { - return context.getClientId(); + return context != null ? context.getClientId() : null; } @Override diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/OpenwirePluginTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/OpenwirePluginTest.java index fa7052dafd..d0206a7be5 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/OpenwirePluginTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/OpenwirePluginTest.java @@ -60,9 +60,12 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; +import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.server.ActiveMQServer; +import org.apache.activemq.artemis.core.server.plugin.ActiveMQServerPlugin; import org.apache.activemq.artemis.core.settings.impl.AddressSettings; +import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection; import org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest; import org.junit.Test; @@ -76,6 +79,19 @@ public class OpenwirePluginTest extends BasicOpenWireTest { long maxAddressSize, Map settings) { ActiveMQServer server = super.createServer(realFiles, configuration, pageSize, maxAddressSize, settings); server.registerBrokerPlugin(verifier); + server.registerBrokerPlugin(new ActiveMQServerPlugin() { + + @Override + public void afterCreateConnection(RemotingConnection connection) throws ActiveMQException { + try { + //Verify that calling getClientID() before initialized doesn't cause an error + //Test for ARTEMIS-1713 + connection.getClientID(); + } catch (Exception e) { + throw new ActiveMQException(e.getMessage()); + } + } + }); configuration.getAddressesSettings().put("autoCreated", new AddressSettings().setAutoDeleteAddresses(true) .setAutoDeleteQueues(true).setAutoCreateQueues(true).setAutoCreateAddresses(true)); @@ -83,7 +99,7 @@ public class OpenwirePluginTest extends BasicOpenWireTest { return server; } - @Test + @Test(timeout = 10000) public void testAckedMessageAreConsumed() throws JMSException { connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); @@ -119,7 +135,7 @@ public class OpenwirePluginTest extends BasicOpenWireTest { } - @Test + @Test(timeout = 10000) public void testAutoCreatedQueue() throws JMSException { connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);