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 2016/01/15 19:15:03 UTC

groovy git commit: GROOVY-7105: Add try/catch for NoClassDefFoundError in CachedSAMClass (closes #239)

Repository: groovy
Updated Branches:
  refs/heads/master 0d3f40b55 -> b7cb15839


GROOVY-7105: Add try/catch for NoClassDefFoundError in CachedSAMClass (closes #239)

SAM method resolution can cause loading of classes used in method arguments (or as a return type).

When such a class is not present on a CLASSPATH, it causes a NoClassDefFoundError even though the class may actually not be needed for program execution.

This solution suppresses the NoClassDefFoundError when resolving SAM method, but in the case when the class is really needed for execution, it will throw the exception then.


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

Branch: refs/heads/master
Commit: b7cb158395a2e141c12238a7491a073081f8d27b
Parents: 0d3f40b
Author: belkaram <ra...@gmail.com>
Authored: Wed Jan 13 17:03:45 2016 +0100
Committer: pascalschumacher <pa...@gmx.net>
Committed: Fri Jan 15 19:11:46 2016 +0100

----------------------------------------------------------------------
 .../groovy/reflection/stdclasses/CachedSAMClass.java         | 8 ++++++++
 1 file changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/b7cb1583/src/main/org/codehaus/groovy/reflection/stdclasses/CachedSAMClass.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/reflection/stdclasses/CachedSAMClass.java b/src/main/org/codehaus/groovy/reflection/stdclasses/CachedSAMClass.java
index 13a02f8..5988db0 100644
--- a/src/main/org/codehaus/groovy/reflection/stdclasses/CachedSAMClass.java
+++ b/src/main/org/codehaus/groovy/reflection/stdclasses/CachedSAMClass.java
@@ -157,6 +157,14 @@ public class CachedSAMClass extends CachedClass {
      * @return null if nothing was found, the method otherwise
      */
     public static Method getSAMMethod(Class<?> c) {
+      try {
+        return getSAMMethodImpl(c);
+      } catch (NoClassDefFoundError ignore) {
+        return null;
+      }
+    }
+
+    private static Method getSAMMethodImpl(Class<?> c) {
         // SAM = single public abstract method
         // if the class is not abstract there is no abstract method
         if (!Modifier.isAbstract(c.getModifiers())) return null;