|
|
|
@ -63,17 +63,16 @@ public class ReflectUtils { |
|
|
|
|
|
|
|
|
|
|
|
private static final Method classLoaderDefineClassMethod; |
|
|
|
private static final Method classLoaderDefineClassMethod; |
|
|
|
|
|
|
|
|
|
|
|
private static final ProtectionDomain PROTECTION_DOMAIN; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Throwable THROWABLE; |
|
|
|
private static final Throwable THROWABLE; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final ProtectionDomain PROTECTION_DOMAIN; |
|
|
|
|
|
|
|
|
|
|
|
private static final List<Method> OBJECT_METHODS = new ArrayList<Method>(); |
|
|
|
private static final List<Method> OBJECT_METHODS = new ArrayList<Method>(); |
|
|
|
|
|
|
|
|
|
|
|
static { |
|
|
|
static { |
|
|
|
Method privateLookupIn; |
|
|
|
Method privateLookupIn; |
|
|
|
Method lookupDefineClass; |
|
|
|
Method lookupDefineClass; |
|
|
|
Method classLoaderDefineClass; |
|
|
|
Method classLoaderDefineClass; |
|
|
|
ProtectionDomain protectionDomain; |
|
|
|
|
|
|
|
Throwable throwable = null; |
|
|
|
Throwable throwable = null; |
|
|
|
try { |
|
|
|
try { |
|
|
|
privateLookupIn = (Method) AccessController.doPrivileged(new PrivilegedExceptionAction() { |
|
|
|
privateLookupIn = (Method) AccessController.doPrivileged(new PrivilegedExceptionAction() { |
|
|
|
@ -102,39 +101,37 @@ public class ReflectUtils { |
|
|
|
String.class, byte[].class, Integer.TYPE, Integer.TYPE, ProtectionDomain.class); |
|
|
|
String.class, byte[].class, Integer.TYPE, Integer.TYPE, ProtectionDomain.class); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
protectionDomain = getProtectionDomain(ReflectUtils.class); |
|
|
|
|
|
|
|
AccessController.doPrivileged(new PrivilegedExceptionAction() { |
|
|
|
|
|
|
|
public Object run() throws Exception { |
|
|
|
|
|
|
|
Method[] methods = Object.class.getDeclaredMethods(); |
|
|
|
|
|
|
|
for (Method method : methods) { |
|
|
|
|
|
|
|
if ("finalize".equals(method.getName()) |
|
|
|
|
|
|
|
|| (method.getModifiers() & (Modifier.FINAL | Modifier.STATIC)) > 0) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
OBJECT_METHODS.add(method); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
catch (Throwable t) { |
|
|
|
catch (Throwable t) { |
|
|
|
privateLookupIn = null; |
|
|
|
privateLookupIn = null; |
|
|
|
lookupDefineClass = null; |
|
|
|
lookupDefineClass = null; |
|
|
|
classLoaderDefineClass = null; |
|
|
|
classLoaderDefineClass = null; |
|
|
|
protectionDomain = null; |
|
|
|
|
|
|
|
throwable = t; |
|
|
|
throwable = t; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
privateLookupInMethod = privateLookupIn; |
|
|
|
privateLookupInMethod = privateLookupIn; |
|
|
|
lookupDefineClassMethod = lookupDefineClass; |
|
|
|
lookupDefineClassMethod = lookupDefineClass; |
|
|
|
classLoaderDefineClassMethod = classLoaderDefineClass; |
|
|
|
classLoaderDefineClassMethod = classLoaderDefineClass; |
|
|
|
PROTECTION_DOMAIN = protectionDomain; |
|
|
|
|
|
|
|
THROWABLE = throwable; |
|
|
|
THROWABLE = throwable; |
|
|
|
|
|
|
|
PROTECTION_DOMAIN = getProtectionDomain(ReflectUtils.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AccessController.doPrivileged(new PrivilegedAction() { |
|
|
|
|
|
|
|
public Object run() { |
|
|
|
|
|
|
|
Method[] methods = Object.class.getDeclaredMethods(); |
|
|
|
|
|
|
|
for (Method method : methods) { |
|
|
|
|
|
|
|
if ("finalize".equals(method.getName()) |
|
|
|
|
|
|
|
|| (method.getModifiers() & (Modifier.FINAL | Modifier.STATIC)) > 0) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
OBJECT_METHODS.add(method); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
// SPRING PATCH END
|
|
|
|
// SPRING PATCH END
|
|
|
|
|
|
|
|
|
|
|
|
private static final String[] CGLIB_PACKAGES = { |
|
|
|
private static final String[] CGLIB_PACKAGES = {"java.lang"}; |
|
|
|
"java.lang", |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static { |
|
|
|
static { |
|
|
|
primitives.put("byte", Byte.TYPE); |
|
|
|
primitives.put("byte", Byte.TYPE); |
|
|
|
@ -499,6 +496,7 @@ public class ReflectUtils { |
|
|
|
ProtectionDomain protectionDomain, Class<?> contextClass) throws Exception { |
|
|
|
ProtectionDomain protectionDomain, Class<?> contextClass) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
Class c = null; |
|
|
|
Class c = null; |
|
|
|
|
|
|
|
Throwable t = THROWABLE; |
|
|
|
|
|
|
|
|
|
|
|
// Preferred option: JDK 9+ Lookup.defineClass API if ClassLoader matches
|
|
|
|
// Preferred option: JDK 9+ Lookup.defineClass API if ClassLoader matches
|
|
|
|
if (contextClass != null && contextClass.getClassLoader() == loader && |
|
|
|
if (contextClass != null && contextClass.getClassLoader() == loader && |
|
|
|
@ -516,6 +514,7 @@ public class ReflectUtils { |
|
|
|
// in case of plain LinkageError (class already defined)
|
|
|
|
// in case of plain LinkageError (class already defined)
|
|
|
|
// or IllegalArgumentException (class in different package):
|
|
|
|
// or IllegalArgumentException (class in different package):
|
|
|
|
// fall through to traditional ClassLoader.defineClass below
|
|
|
|
// fall through to traditional ClassLoader.defineClass below
|
|
|
|
|
|
|
|
t = ex; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Throwable ex) { |
|
|
|
catch (Throwable ex) { |
|
|
|
throw new CodeGenerationException(ex); |
|
|
|
throw new CodeGenerationException(ex); |
|
|
|
@ -539,9 +538,11 @@ public class ReflectUtils { |
|
|
|
throw new CodeGenerationException(ex.getTargetException()); |
|
|
|
throw new CodeGenerationException(ex.getTargetException()); |
|
|
|
} |
|
|
|
} |
|
|
|
// in case of UnsupportedOperationException, fall through
|
|
|
|
// in case of UnsupportedOperationException, fall through
|
|
|
|
|
|
|
|
t = ex.getTargetException(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Throwable ex) { |
|
|
|
catch (Throwable ex) { |
|
|
|
// publicDefineClass method not available -> fall through
|
|
|
|
// publicDefineClass method not available -> fall through
|
|
|
|
|
|
|
|
t = ex; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Classic option: protected ClassLoader.defineClass method
|
|
|
|
// Classic option: protected ClassLoader.defineClass method
|
|
|
|
@ -562,6 +563,7 @@ public class ReflectUtils { |
|
|
|
if (!ex.getClass().getName().endsWith("InaccessibleObjectException")) { |
|
|
|
if (!ex.getClass().getName().endsWith("InaccessibleObjectException")) { |
|
|
|
throw new CodeGenerationException(ex); |
|
|
|
throw new CodeGenerationException(ex); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
t = ex; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -584,7 +586,7 @@ public class ReflectUtils { |
|
|
|
|
|
|
|
|
|
|
|
// No defineClass variant available at all?
|
|
|
|
// No defineClass variant available at all?
|
|
|
|
if (c == null) { |
|
|
|
if (c == null) { |
|
|
|
throw new CodeGenerationException(THROWABLE); |
|
|
|
throw new CodeGenerationException(t); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Force static initializers to run.
|
|
|
|
// Force static initializers to run.
|
|
|
|
|