diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java b/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java index 7f9fa6c21f..5c6307af9d 100755 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java @@ -602,7 +602,10 @@ public class TransportConnection implements Connection, Task, CommandVisitor { // Avoid replaying dup commands if (!ss.getProducerIds().contains(info.getProducerId())) { ActiveMQDestination destination = info.getDestination(); - if (destination != null && !AdvisorySupport.isAdvisoryTopic(destination)) { + // Do not check for null here as it would cause the count of max producers to exclude + // anonymous producers. The isAdvisoryTopic method checks for null so it is safe to + // call it from here with a null Destination value. + if (!AdvisorySupport.isAdvisoryTopic(destination)) { if (getProducerCount(connectionId) >= connector.getMaximumProducersAllowedPerConnection()){ throw new IllegalStateException("Can't add producer on connection " + connectionId + ": at maximum limit: " + connector.getMaximumProducersAllowedPerConnection()); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/config/ConfigTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/config/ConfigTest.java index 82b5ebec76..a62ce071a5 100755 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/config/ConfigTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/config/ConfigTest.java @@ -383,6 +383,13 @@ public class ConfigTest { } catch (JMSException expected) { } + // Tests the anonymous producer case also counts. + try { + session.createProducer(null); + fail("Should have got an exception on exceeding MAX_PRODUCERS"); + } catch (JMSException expected) { + } + try { for (int i = 0; i < (MAX_CONSUMERS + 1); i++) { MessageConsumer consumer = session.createConsumer(topic);