groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blackd...@apache.org
Subject 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
Date Tue, 06 Sep 2016 21:13:10 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 0cc5d7d47 -> 71e6258c8


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


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

Branch: refs/heads/master
Commit: 71e6258c8fcd8ae5bea1f5a4d708c42e6bf69519
Parents: 0cc5d7d
Author: Jochen Theodorou <blackdrag@gmx.org>
Authored: Tue Sep 6 23:05:39 2016 +0200
Committer: Jochen Theodorou <blackdrag@gmx.org>
Committed: Tue Sep 6 23:05:39 2016 +0200

----------------------------------------------------------------------
 .../codehaus/groovy/reflection/CachedClass.java | 45 ++++++++++++--------
 .../m12n/ExtensionModuleHelperForTests.groovy   | 11 +++++
 2 files changed, 39 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/71e6258c/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 6b87c2c..9302390 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 {
         }
     };
 
+    // 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/71e6258c/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 298e032..f69c2f7 100644
--- a/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
+++ b/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
@@ -41,6 +41,13 @@ public class ExtensionModuleHelperForTests {
         Set<String> cp = System.getProperty("java.class.path").split(File.pathSeparator)
as Set
         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 {
@@ -56,6 +63,10 @@ public class ExtensionModuleHelperForTests {
                                     pathelement location: it
                                 }
                             }
+                            if (jdk9) {
+                                jvmarg(value: '-addmods')
+                                jvmarg(value: 'java.xml.bind')
+                            }
                         }
                 )
             }


Mime
View raw message