tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkupp...@apache.org
Subject [2/3] tinkerpop git commit: Fixed possible classcastexception in groovy ScriptEngine
Date Fri, 18 Aug 2017 21:12:33 GMT
Fixed possible classcastexception in groovy ScriptEngine

Minor adjustment to exceptions. Without this change you'd end up with a ClassCastExeption
and error out, so this shouldn't be adding any new behavior. Logic is the same as before,
without the possible failure condition CTR


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

Branch: refs/heads/TINKERPOP-1748
Commit: 43f5afa0725c42bdde72049e5d88720bdce6e787
Parents: ad12776
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Thu Aug 17 15:04:44 2017 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Thu Aug 17 15:04:44 2017 -0400

----------------------------------------------------------------------
 .../groovy/jsr223/GremlinGroovyScriptEngine.java     | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/43f5afa0/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
index d52e104..a74d4d9 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GremlinGroovyScriptEngine.java
@@ -30,6 +30,7 @@ import groovy.lang.MissingMethodException;
 import groovy.lang.MissingPropertyException;
 import groovy.lang.Script;
 import groovy.lang.Tuple;
+import org.apache.commons.lang.exception.ExceptionUtils;
 import org.apache.tinkerpop.gremlin.groovy.CompilerCustomizerProvider;
 import org.apache.tinkerpop.gremlin.groovy.DefaultImportCustomizerProvider;
 import org.apache.tinkerpop.gremlin.groovy.EmptyImportCustomizerProvider;
@@ -580,7 +581,7 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
     public CompiledScript compile(final String scriptSource) throws ScriptException {
         try {
             return new GroovyCompiledScript(this, getScriptClass(scriptSource));
-        } catch (CompilationFailedException e) {
+        } catch (Exception e) {
             throw new ScriptException(e);
         }
     }
@@ -733,11 +734,19 @@ public class GremlinGroovyScriptEngine extends GroovyScriptEngineImpl
         return classMap.stats().totalLoadTime();
     }
 
-    Class getScriptClass(final String script) throws CompilationFailedException {
+    Class getScriptClass(final String script) throws Exception {
         try {
             return classMap.get(script).get();
         } catch (ExecutionException e) {
-            throw ((CompilationFailedException)e.getCause());
+            final Throwable t = e.getCause();
+
+            // more often than not the cause is a compilation problem but there might be
other failures that can
+            // occur in which case, just throw the ExecutionException as-is and let it bubble
up as i'm not sure
+            // what the specific handling should be
+            if (t instanceof CompilationFailedException)
+                throw (CompilationFailedException) t;
+            else
+                throw e;
         } catch (InterruptedException e) {
             //This should never happen as the future should completed before it is returned
to the us.
             throw new AssertionError();


Mime
View raw message