Repository: activemq-artemis
Updated Branches:
  refs/heads/master 586abba94 -> 0a1e6bdd5


Fix NPE in empty InExpression.toString


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/6fbafc44
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/6fbafc44
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/6fbafc44

Branch: refs/heads/master
Commit: 6fbafc4441791bd3883e695f395ef35a4d36e62e
Parents: 586abba
Author: Ville Skyttä <ville.sky...@iki.fi>
Authored: Thu Oct 13 00:20:59 2016 +0300
Committer: Ville Skyttä <ville.sky...@iki.fi>
Committed: Thu Oct 13 00:25:29 2016 +0300

----------------------------------------------------------------------
 .../artemis/selector/filter/UnaryExpression.java       | 13 +++++--------
 .../artemis/selector/filter/UnaryExpressionTest.java   | 11 +++++++++++
 2 files changed, 16 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6fbafc44/artemis-selector/src/main/java/org/apache/activemq/artemis/selector/filter/UnaryExpression.java
----------------------------------------------------------------------
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 4c106bd..e70de83 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<Object> t;
-      if (elements.size() == 0) {
-         t = null;
-      } else if (elements.size() < 5) {
-         t = elements;
+      final Collection<Object> inList;
+      if (elements.size() < 5) {
+         inList = elements;
       } else {
-         t = new HashSet<>(elements);
+         inList = new HashSet<>(elements);
       }
-      final Collection<Object> 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

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/6fbafc44/artemis-selector/src/test/java/org/apache/activemq/artemis/selector/filter/UnaryExpressionTest.java
----------------------------------------------------------------------
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 6e6ab43..8f1b1a1 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.<Object>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+.*"));
+   }
 }

Reply via email to