diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/SelectorAwareVirtualTopicInterceptor.java b/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/SelectorAwareVirtualTopicInterceptor.java index b528f40f0f..fdbfbe6aba 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/SelectorAwareVirtualTopicInterceptor.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/region/virtual/SelectorAwareVirtualTopicInterceptor.java @@ -76,15 +76,17 @@ public class SelectorAwareVirtualTopicInterceptor extends VirtualTopicIntercepto if (cache != null) { final Set selectors = cache.getSelector(dest.getActiveMQDestination().getQualifiedName()); - for (String selector : selectors) { - try { - final BooleanExpression expression = getExpression(selector); - matches = expression.matches(msgContext); - if (matches) { - return true; + if (selectors != null) { + for (String selector : selectors) { + try { + final BooleanExpression expression = getExpression(selector); + matches = expression.matches(msgContext); + if (matches) { + return true; + } + } catch (Exception e) { + LOG.error(e.getMessage(), e); } - } catch (Exception e) { - LOG.error(e.getMessage(), e); } } } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/TwoBrokerVirtualTopicSelectorAwareForwardingTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/TwoBrokerVirtualTopicSelectorAwareForwardingTest.java index d1be900e76..697f55bc63 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/TwoBrokerVirtualTopicSelectorAwareForwardingTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/TwoBrokerVirtualTopicSelectorAwareForwardingTest.java @@ -578,6 +578,23 @@ public class TwoBrokerVirtualTopicSelectorAwareForwardingTest extends } + public void testSelectorNoMatchInCache() throws Exception { + clearSelectorCacheFiles(); + + // have the cache ignoreWildcardSelectors + final BrokerService brokerA = brokers.get("BrokerA").broker; + ((SubQueueSelectorCacheBrokerPlugin)brokerA.getPlugins()[0]).setIgnoreWildcardSelectors(true); + + startAllBrokers(); + + ActiveMQDestination consumerBQueue = createDestination("Consumer.B.VirtualTopic.tempTopic", false); + + MessageConsumer nonMatchingConsumer = createConsumer("BrokerA", consumerBQueue, "foo = 'bar%'"); + + ActiveMQTopic virtualTopic = new ActiveMQTopic("VirtualTopic.tempTopic"); + sendMessages("BrokerA", virtualTopic, 1, asMap("foo", "notBar")); + } + private HashMap asMap(String key, Object value) { HashMap rc = new HashMap(1); rc.put(key, value);