You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2018/03/22 23:39:41 UTC

[1/2] groovy git commit: GROOVY-8494: Calling Stream.of from groovy class in JDK 9 fails (fix for jdk6)

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 00af138c0 -> 6e8ac9d4b


GROOVY-8494: Calling Stream.of from groovy class in JDK 9 fails (fix for jdk6)


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 330d590aa145f240cb7a590e9eb7bec4087c1f65
Parents: 00af138
Author: paulk <pa...@asert.com.au>
Authored: Fri Mar 23 09:27:05 2018 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Fri Mar 23 09:27:05 2018 +1000

----------------------------------------------------------------------
 build.gradle | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/330d590a/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index a1ac1df..834cba0 100644
--- a/build.gradle
+++ b/build.gradle
@@ -261,6 +261,7 @@ sourceSets {
             if (!JavaVersion.current().isJava7Compatible()) {
                 exclude '**/indy/*'
                 exclude '**/v7/*'
+                exclude '**/v8/*'
                 exclude '**/vm7/*'
             }
         }
@@ -272,6 +273,7 @@ sourceSets {
             if (!JavaVersion.current().isJava7Compatible()) {
                 exclude '**/indy/*'
                 exclude '**/v7/*'
+                exclude '**/v8/*'
                 exclude '**/vm7/*'
             }
         }


[2/2] groovy git commit: GROOVY-8514: NullPointerException in class MissingMethodException (closes #675)

Posted by pa...@apache.org.
GROOVY-8514: NullPointerException in class MissingMethodException (closes #675)


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 6e8ac9d4b797b9cb5d653c6341a5f4dda63c885c
Parents: 330d590
Author: paulk <pa...@asert.com.au>
Authored: Mon Mar 19 22:46:07 2018 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Fri Mar 23 09:39:25 2018 +1000

----------------------------------------------------------------------
 .../groovy/lang/MissingMethodException.java     |  3 ++-
 .../groovy/jsr223/GroovyScriptEngineImpl.java   | 18 +++++++++++++-
 .../codehaus/groovy/jsr223/JSR223Test.groovy    | 25 ++++++++++++++++++++
 3 files changed, 44 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/6e8ac9d4/src/main/groovy/lang/MissingMethodException.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/MissingMethodException.java b/src/main/groovy/lang/MissingMethodException.java
index efc45fb..f8cad0d 100644
--- a/src/main/groovy/lang/MissingMethodException.java
+++ b/src/main/groovy/lang/MissingMethodException.java
@@ -31,6 +31,7 @@ import org.codehaus.groovy.runtime.MethodRankHelper;
  */
 public class MissingMethodException extends GroovyRuntimeException {
 
+    private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
     private final String method;
     private final Class type;
     private final boolean isStatic;
@@ -50,7 +51,7 @@ public class MissingMethodException extends GroovyRuntimeException {
         this.method = method;
         this.type = type;
         this.isStatic = isStatic;
-        this.arguments = arguments;
+        this.arguments = arguments == null ? EMPTY_OBJECT_ARRAY : arguments;
     }
 
     public String getMessage() {

http://git-wip-us.apache.org/repos/asf/groovy/blob/6e8ac9d4/subprojects/groovy-jsr223/src/main/java/org/codehaus/groovy/jsr223/GroovyScriptEngineImpl.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-jsr223/src/main/java/org/codehaus/groovy/jsr223/GroovyScriptEngineImpl.java b/subprojects/groovy-jsr223/src/main/java/org/codehaus/groovy/jsr223/GroovyScriptEngineImpl.java
index 03fc49e..2c9e633 100644
--- a/subprojects/groovy-jsr223/src/main/java/org/codehaus/groovy/jsr223/GroovyScriptEngineImpl.java
+++ b/subprojects/groovy-jsr223/src/main/java/org/codehaus/groovy/jsr223/GroovyScriptEngineImpl.java
@@ -367,6 +367,22 @@ public class GroovyScriptEngineImpl extends AbstractScriptEngine implements Comp
         }
     }
 
+    private Object invokeImplSafe(Object thiz, String name, Object... args) {
+        if (name == null) {
+            throw new NullPointerException("method name is null");
+        }
+
+        try {
+            if (thiz != null) {
+                return InvokerHelper.invokeMethod(thiz, name, args);
+            } else {
+                return callGlobal(name, args);
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     // call the script global function of the given name
     private Object callGlobal(String name, Object[] args) {
         return callGlobal(name, args, context);
@@ -404,7 +420,7 @@ public class GroovyScriptEngineImpl extends AbstractScriptEngine implements Comp
                 new InvocationHandler() {
                     public Object invoke(Object proxy, Method m, Object[] args)
                             throws Throwable {
-                        return invokeImpl(thiz, m.getName(), args);
+                        return invokeImplSafe(thiz, m.getName(), args);
                     }
                 });
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/6e8ac9d4/subprojects/groovy-jsr223/src/test/groovy/org/codehaus/groovy/jsr223/JSR223Test.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-jsr223/src/test/groovy/org/codehaus/groovy/jsr223/JSR223Test.groovy b/subprojects/groovy-jsr223/src/test/groovy/org/codehaus/groovy/jsr223/JSR223Test.groovy
index d680130..ce63254 100644
--- a/subprojects/groovy-jsr223/src/test/groovy/org/codehaus/groovy/jsr223/JSR223Test.groovy
+++ b/subprojects/groovy-jsr223/src/test/groovy/org/codehaus/groovy/jsr223/JSR223Test.groovy
@@ -220,4 +220,29 @@ class JSR223Test extends GroovyTestCase {
         assert engine.getFactory() == factory
     }
 
+    void testGetInterfaceScenarios() {
+        assertScript '''
+        interface Test { def foo(); def bar(); def baz() }
+        def engine = new javax.script.ScriptEngineManager().getEngineByName("groovy")
+        engine.eval("def foo() { 42 }")
+        engine.eval("def bar() { throw new Exception('Boom!') }")
+        def test = engine.getInterface(Test)
+        assert test.foo() == 42
+
+        try {
+            test.bar()
+            assert false
+        } catch(RuntimeException re) {
+            assert re.message.endsWith('Boom!')
+        }
+
+        try {
+            test.baz()
+            assert false
+        } catch(RuntimeException re) {
+            assert re.cause.class.name.endsWith('MissingMethodException')
+        }
+        '''
+    }
+
 }