found a bug in GraphFilterStrategyTest that caused the bindings to get messed 
up. Basically, a ) was missing and until() was inside the repeat().


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/b70ba903
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/b70ba903
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/b70ba903

Branch: refs/heads/master
Commit: b70ba903f40b3bffac0061c4a56f1992b55ee8ef
Parents: 84a82fb
Author: Marko A. Rodriguez <okramma...@gmail.com>
Authored: Tue Nov 29 14:40:13 2016 -0700
Committer: Marko A. Rodriguez <okramma...@gmail.com>
Committed: Tue Nov 29 14:40:13 2016 -0700

----------------------------------------------------------------------
 .../gremlin/process/traversal/Bindings.java         | 14 +++++++++-----
 .../gremlin/process/traversal/Bytecode.java         | 16 +++++++---------
 .../optimization/GraphFilterStrategyTest.java       |  2 +-
 3 files changed, 17 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b70ba903/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bindings.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bindings.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bindings.java
index ba31e21..3359942 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bindings.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bindings.java
@@ -19,6 +19,7 @@
 
 package org.apache.tinkerpop.gremlin.process.traversal;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -41,23 +42,26 @@ import java.util.Map;
  */
 public final class Bindings {
 
-    private final Map<Object, String> map = new HashMap<>();
+    private static final ThreadLocal<Map<Object, String>> MAP = new 
ThreadLocal<>();
 
     public <V> V of(final String variable, final V value) {
-        this.map.put(value, variable);
+        if (null == MAP.get())
+            MAP.set(new HashMap<>());
+        MAP.get().put(value, variable);
         return value;
     }
 
     protected <V> String getBoundVariable(final V value) {
-        return this.map.get(value);
+        return null == MAP.get() ? null : MAP.get().get(value);
     }
 
     protected void clear() {
-        this.map.clear();
+        if (null != MAP.get())
+            MAP.get().clear();
     }
 
     @Override
     public String toString() {
-        return this.map.toString();
+        return null == MAP.get() ? Collections.emptyMap().toString() : 
MAP.get().toString();
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b70ba903/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java
index 567e282..11f6341 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java
@@ -52,7 +52,7 @@ public final class Bytecode implements Cloneable, 
Serializable {
 
     private List<Instruction> sourceInstructions = new ArrayList<>();
     private List<Instruction> stepInstructions = new ArrayList<>();
-    private static transient ThreadLocal<Bindings> BINDINGS = new 
ThreadLocal<>();
+    private final transient Bindings bindings = new Bindings();
 
     /**
      * Add a {@link TraversalSource} instruction to the bytecode.
@@ -61,9 +61,7 @@ public final class Bytecode implements Cloneable, 
Serializable {
      * @param arguments  the traversal source method arguments
      */
     public void addSource(final String sourceName, final Object... arguments) {
-        if (sourceName.equals(TraversalSource.Symbols.withBindings)) {
-            BINDINGS.set((Bindings) arguments[0]);
-        } else if 
(sourceName.equals(TraversalSource.Symbols.withoutStrategies)) {
+        if (sourceName.equals(TraversalSource.Symbols.withoutStrategies)) {
             final Class<TraversalStrategy>[] classes = new 
Class[arguments.length];
             for (int i = 0; i < arguments.length; i++) {
                 classes[i] = arguments[i] instanceof TraversalStrategyProxy ?
@@ -71,10 +69,10 @@ public final class Bytecode implements Cloneable, 
Serializable {
                         (Class) arguments[i];
             }
             this.sourceInstructions.add(new Instruction(sourceName, classes));
-        } else {
+        } else if (!sourceName.equals(TraversalSource.Symbols.withBindings)) {
             this.sourceInstructions.add(new Instruction(sourceName, 
flattenArguments(arguments)));
         }
-        if (null != BINDINGS.get()) BINDINGS.get().clear();
+        this.bindings.clear();
     }
 
     /**
@@ -85,7 +83,7 @@ public final class Bytecode implements Cloneable, 
Serializable {
      */
     public void addStep(final String stepName, final Object... arguments) {
         this.stepInstructions.add(new Instruction(stepName, 
flattenArguments(arguments)));
-        if (null != BINDINGS.get()) BINDINGS.get().clear();
+        this.bindings.clear();
     }
 
     /**
@@ -272,8 +270,8 @@ public final class Bytecode implements Cloneable, 
Serializable {
     }
 
     private final Object convertArgument(final Object argument, final boolean 
searchBindings) {
-        if (searchBindings && null != BINDINGS.get()) {
-            final String variable = BINDINGS.get().getBoundVariable(argument);
+        if (searchBindings) {
+            final String variable = this.bindings.getBoundVariable(argument);
             if (null != variable)
                 return new Binding<>(variable, convertArgument(argument, 
false));
         }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b70ba903/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/optimization/GraphFilterStrategyTest.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/optimization/GraphFilterStrategyTest.java
 
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/optimization/GraphFilterStrategyTest.java
index e2deeed..cc38df9 100644
--- 
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/optimization/GraphFilterStrategyTest.java
+++ 
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/optimization/GraphFilterStrategyTest.java
@@ -61,7 +61,7 @@ public class GraphFilterStrategyTest {
                 {__.out("created"), __.outE("created")},
                 {__.in("created", "knows"), __.inE("created", "knows")},
                 {__.V().both("created"), __.bothE("created")},
-                
{__.V().out("created").repeat(__.both("knows").until(__.inE("bought", 
"likes"))).outE("likes"), __.union(__.outE("created"), __.bothE("bought", 
"knows", "likes"))},
+                
{__.V().out("created").repeat(__.both("knows")).until(__.inE("bought", 
"likes")).outE("likes"), __.union(__.outE("created"), __.bothE("bought", 
"knows", "likes"))},
                 {__.union(__.inE("created"), __.bothE()), null},
                 {__.union(__.inE("created"), __.outE("created")), 
__.bothE("created")},
                 {__.union(__.inE("knows"), __.outE("created")), 
__.union(__.outE("created"), __.bothE("knows"))},

Reply via email to