diff --git a/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/UnaryExpression.java b/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/UnaryExpression.java index 4c106bd050..e70de83861 100755 --- a/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/UnaryExpression.java +++ b/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/UnaryExpression.java @@ -61,15 +61,12 @@ public abstract class UnaryExpression implements Expression { final boolean not) { // Use a HashSet if there are many elements. - Collection t; - if (elements.size() == 0) { - t = null; - } else if (elements.size() < 5) { - t = elements; + final Collection inList; + if (elements.size() < 5) { + inList = elements; } else { - t = new HashSet<>(elements); + inList = new HashSet<>(elements); } - final Collection inList = t; return new BooleanUnaryExpression(right) { @Override @@ -83,7 +80,7 @@ public abstract class UnaryExpression implements Expression { return null; } - return (inList != null && inList.contains(rvalue)) ^ not; + return inList.contains(rvalue) ^ not; } @Override diff --git a/artemis-selector/src/test/java/org/apache/activemq/artemis/selector/filter/UnaryExpressionTest.java b/artemis-selector/src/test/java/org/apache/activemq/artemis/selector/filter/UnaryExpressionTest.java index 6e6ab43c64..8f1b1a19bc 100755 --- a/artemis-selector/src/test/java/org/apache/activemq/artemis/selector/filter/UnaryExpressionTest.java +++ b/artemis-selector/src/test/java/org/apache/activemq/artemis/selector/filter/UnaryExpressionTest.java @@ -16,6 +16,8 @@ */ package org.apache.activemq.artemis.selector.filter; +import java.util.Collections; + import org.apache.activemq.artemis.selector.impl.SelectorParser; import org.junit.Assert; import org.junit.Test; @@ -30,4 +32,13 @@ public class UnaryExpressionTest { Assert.assertTrue("Created unary expression 2", expr2 instanceof UnaryExpression); Assert.assertEquals("Unary expressions are equal", expr1, expr2); } + + @Test + public void testInExpressionToString() throws Exception { + BooleanExpression expr; + expr = UnaryExpression.createInExpression(new PropertyExpression("foo"), Collections.singletonList("bar"), false); + Assert.assertTrue(expr.toString().matches("foo\\s+IN\\s+.*bar.*")); + expr = UnaryExpression.createInExpression(new PropertyExpression("foo"), Collections.emptyList(), false); + Assert.assertTrue(expr.toString().matches("foo\\s+IN\\s+.*")); + } }