]> source.dussan.org Git - aspectj.git/commitdiff
On JDK11 call the defineClass variant with a ProtectionDomain param
authorAndy Clement <aclement@pivotal.io>
Fri, 11 Jan 2019 23:49:49 +0000 (15:49 -0800)
committerAndy Clement <aclement@pivotal.io>
Fri, 11 Jan 2019 23:49:49 +0000 (15:49 -0800)
This alters the defineClass used when loadtime weaving and defining
'extra' classes (e.g. closures). This change causes us to call
the defineClass() method variant on ClassLoader that takes a
protection domain, so it should share the same protection domain as
the class for which the extra class was generated.

Issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=542421

loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java

index c4c1ba3ae5b565d679832552c70ed0c95044f79e..f67b0f3adca32f1793ab5d14f63ba4840bdd80b9 100644 (file)
@@ -1054,11 +1054,11 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
        private static synchronized void initializeForJava11() {
                if (initializedForJava11) return;
                try {
-                       // MethodType defineClassMethodType = MethodType.methodType(Class.class, new Class[]{String.class, byte[].class, int.class, int.class});
+                       // MethodType defineClassMethodType = MethodType.methodType(Class.class, new Class[]{String.class, byte[].class, int.class, int.class, ProtectionDomain.class});
                        Class<?> methodType_Class = Class.forName("java.lang.invoke.MethodType");
                        Method methodTypeMethodOnMethodTypeClass = methodType_Class.getDeclaredMethod("methodType", Class.class,Class[].class);
                        methodTypeMethodOnMethodTypeClass.setAccessible(true);
-                       Object defineClassMethodType = methodTypeMethodOnMethodTypeClass.invoke(null, Class.class, new Class[] {String.class,byte[].class,int.class,int.class});
+                       Object defineClassMethodType = methodTypeMethodOnMethodTypeClass.invoke(null, Class.class, new Class[] {String.class,byte[].class,int.class,int.class,ProtectionDomain.class});
 
                        // MethodHandles.Lookup methodHandlesLookup = MethodHandles.lookup();
                        Class<?> methodHandles_Class = Class.forName("java.lang.invoke.MethodHandles");
@@ -1099,9 +1099,9 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
                                if (!initializedForJava11) {
                                        initializeForJava11();
                                }
-                               // Do this: clazz = defineClassMethodHandle.bindTo(loader).invokeWithArguments(name, bytes, 0, bytes.length);
+                               // Do this: clazz = defineClassMethodHandle.bindTo(loader).invokeWithArguments(name, bytes, 0, bytes.length, protectionDomain);
                                Object o = bindTo_Method.invoke(defineClassMethodHandle,loader);
-                               clazz = invokeWithArguments_Method.invoke(o, new Object[] {new Object[] {name, bytes, 0, bytes.length}});
+                               clazz = invokeWithArguments_Method.invoke(o, new Object[] {new Object[] {name, bytes, 0, bytes.length, protectionDomain}});
                            
                        } catch (Throwable t) {
                                t.printStackTrace(System.err);