You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by bl...@apache.org on 2016/10/03 16:34:14 UTC

[1/2] groovy git commit: JDK9: fix setup for extension module tests and fix setting accessibility for methods and fields, as those may now only partially available

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 4df8b652a -> ce957cdd6


JDK9: fix setup for extension module tests and fix setting accessibility for methods and fields, as those may now only partially available

Conflicts:
	src/main/org/codehaus/groovy/reflection/CachedClass.java


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 55cdd8f4886793ec4c456260f20640ed4793539e
Parents: 4df8b65
Author: Jochen Theodorou <bl...@gmx.org>
Authored: Tue Sep 6 23:05:39 2016 +0200
Committer: Jochen Theodorou <bl...@gmx.org>
Committed: Mon Oct 3 18:32:54 2016 +0200

----------------------------------------------------------------------
 .../codehaus/groovy/reflection/CachedClass.java | 47 ++++++++++++--------
 .../m12n/ExtensionModuleHelperForTests.groovy   | 11 +++++
 2 files changed, 40 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/55cdd8f4/src/main/org/codehaus/groovy/reflection/CachedClass.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/reflection/CachedClass.java b/src/main/org/codehaus/groovy/reflection/CachedClass.java
index afba52a..1674294 100644
--- a/src/main/org/codehaus/groovy/reflection/CachedClass.java
+++ b/src/main/org/codehaus/groovy/reflection/CachedClass.java
@@ -28,6 +28,7 @@ import org.codehaus.groovy.util.FastArray;
 import org.codehaus.groovy.util.ReferenceBundle;
 
 import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Array;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
@@ -48,17 +49,10 @@ public class CachedClass {
     private final LazyReference<CachedField[]> fields = new LazyReference<CachedField[]>(softBundle) {
         public CachedField[] initValue() {
             final Field[] declaredFields = (Field[])
-               AccessController.doPrivileged(new PrivilegedAction/*<Field[]>*/() {
-                   public /*Field[]*/ Object run() {
-                       final Field[] df = getTheClass().getDeclaredFields();
-                       try {
-                           AccessibleObject.setAccessible(df, true);
-                       } catch (SecurityException e) {
-                           // swallow for strict security managers
-                       } catch (RuntimeException re) {
-                           // test for JDK9 JIGSAW
-                           if (!"java.lang.reflect.InaccessibleObjectException".equals(re.getClass().getName())) throw re;
-                       }
+               AccessController.doPrivileged(new PrivilegedAction<Field[]>() {
+                   public Field[] run() {
+                       Field[] df = getTheClass().getDeclaredFields();
+                       df = (Field[]) makeAccessible(df);
                        return df;                                                   
                    }
                });
@@ -84,18 +78,35 @@ public class CachedClass {
         }
     };
 
-    private LazyReference<CachedMethod[]> methods = new LazyReference<CachedMethod[]>(softBundle) {
+    // to be run in PrivilegedAction!
+    private static AccessibleObject[] makeAccessible(final AccessibleObject[] aoa) {
+        try {
+            AccessibleObject.setAccessible(aoa, true);
+            return aoa;
+        } catch (Throwable outer) {
+            // swallow for strict security managers, module systems, android or others,
+            // but try one-by-one to get the allowed ones at least
+            final ArrayList<AccessibleObject> ret = new ArrayList<>(aoa.length);
+            for (final AccessibleObject ao : aoa) {
+                try {
+                    ao.setAccessible(true);
+                    ret.add(ao);
+                } catch (Throwable inner) {
+                    // swallow for strict security managers, module systems, android or others
+                }
+            }
+            return ret.toArray((AccessibleObject[]) Array.newInstance(aoa.getClass().getComponentType(), ret.size()));
+        }
+    }
+
+    private final LazyReference<CachedMethod[]> methods = new LazyReference<CachedMethod[]>(softBundle) {
         public CachedMethod[] initValue() {
             final Method[] declaredMethods = (Method[])
                AccessController.doPrivileged(new PrivilegedAction/*<Method[]>*/() {
                    public /*Method[]*/ Object run() {
                        try {
-                           final Method[] dm = getTheClass().getDeclaredMethods();
-                           try {
-                               AccessibleObject.setAccessible(dm, true);
-                           } catch (SecurityException e) {
-                               // swallow for strict security managers
-                           }
+                           Method[] dm = getTheClass().getDeclaredMethods();
+                           dm = (Method[]) makeAccessible(dm);
                            return dm;
                        } catch (Throwable e) {
                            // Typically, Android can throw ClassNotFoundException

http://git-wip-us.apache.org/repos/asf/groovy/blob/55cdd8f4/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy b/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
index b2cb542..9f97a7e 100644
--- a/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
+++ b/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
@@ -47,6 +47,13 @@ public class ExtensionModuleHelperForTests {
         Set<String> cp = ((URLClassLoader)cl).URLs.collect{ new File(it.toURI()).absolutePath}
         cp << baseDir.absolutePath
 
+        boolean jdk9 = false;
+        try {
+            jdk9 = this.classLoader.loadClass("java.lang.reflect.Module") != null
+        } catch (e) {
+            throw e
+        }
+
         def ant = new AntBuilder()
         try {
             ant.with {
@@ -62,6 +69,10 @@ public class ExtensionModuleHelperForTests {
                                     pathelement location: it
                                 }
                             }
+                            if (jdk9) {
+                                jvmarg(value: '-addmods')
+                                jvmarg(value: 'java.xml.bind')
+                            }
                         }
                 )
             }


[2/2] groovy git commit: fix test helper so JDK detection doesn't fail when run on pre-JDK9 VMs

Posted by bl...@apache.org.
fix test helper so JDK detection doesn't fail when run on pre-JDK9 VMs


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

Branch: refs/heads/GROOVY_2_4_X
Commit: ce957cdd68091012cc23a6ab1569b6a6d225e9a0
Parents: 55cdd8f
Author: John Wagenleitner <jw...@apache.org>
Authored: Wed Sep 7 11:05:24 2016 -0700
Committer: Jochen Theodorou <bl...@gmx.org>
Committed: Mon Oct 3 18:33:03 2016 +0200

----------------------------------------------------------------------
 .../groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/ce957cdd/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy b/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
index 9f97a7e..fdda30f 100644
--- a/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
+++ b/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
@@ -51,7 +51,7 @@ public class ExtensionModuleHelperForTests {
         try {
             jdk9 = this.classLoader.loadClass("java.lang.reflect.Module") != null
         } catch (e) {
-            throw e
+            // ignore
         }
 
         def ant = new AntBuilder()