Merge branch '5.3.x'
# Conflicts: # spring-core/src/main/java/org/springframework/cglib/core/ReflectUtils.java
This commit is contained in:
@@ -55,43 +55,40 @@ public class ReflectUtils {
|
||||
|
||||
private static final Method classLoaderDefineClassMethod;
|
||||
|
||||
private static final ProtectionDomain PROTECTION_DOMAIN;
|
||||
|
||||
private static final Throwable THROWABLE;
|
||||
|
||||
private static final ProtectionDomain PROTECTION_DOMAIN;
|
||||
|
||||
private static final List<Method> OBJECT_METHODS = new ArrayList<Method>();
|
||||
|
||||
// SPRING PATCH BEGIN
|
||||
static {
|
||||
Method classLoaderDefineClass;
|
||||
ProtectionDomain protectionDomain;
|
||||
Throwable throwable = null;
|
||||
try {
|
||||
classLoaderDefineClass = ClassLoader.class.getDeclaredMethod("defineClass",
|
||||
String.class, byte[].class, Integer.TYPE, Integer.TYPE, ProtectionDomain.class);
|
||||
protectionDomain = getProtectionDomain(ReflectUtils.class);
|
||||
for (Method method : Object.class.getDeclaredMethods()) {
|
||||
if ("finalize".equals(method.getName())
|
||||
|| (method.getModifiers() & (Modifier.FINAL | Modifier.STATIC)) > 0) {
|
||||
continue;
|
||||
}
|
||||
OBJECT_METHODS.add(method);
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
classLoaderDefineClass = null;
|
||||
protectionDomain = null;
|
||||
throwable = t;
|
||||
}
|
||||
|
||||
classLoaderDefineClassMethod = classLoaderDefineClass;
|
||||
PROTECTION_DOMAIN = protectionDomain;
|
||||
THROWABLE = throwable;
|
||||
PROTECTION_DOMAIN = getProtectionDomain(ReflectUtils.class);
|
||||
|
||||
for (Method method : Object.class.getDeclaredMethods()) {
|
||||
if ("finalize".equals(method.getName())
|
||||
|| (method.getModifiers() & (Modifier.FINAL | Modifier.STATIC)) > 0) {
|
||||
continue;
|
||||
}
|
||||
OBJECT_METHODS.add(method);
|
||||
}
|
||||
}
|
||||
// SPRING PATCH END
|
||||
|
||||
private static final String[] CGLIB_PACKAGES = {
|
||||
"java.lang",
|
||||
};
|
||||
private static final String[] CGLIB_PACKAGES = {"java.lang"};
|
||||
|
||||
static {
|
||||
primitives.put("byte", Byte.TYPE);
|
||||
@@ -444,6 +441,7 @@ public class ReflectUtils {
|
||||
ProtectionDomain protectionDomain, Class<?> contextClass) throws Exception {
|
||||
|
||||
Class c = null;
|
||||
Throwable t = THROWABLE;
|
||||
|
||||
// Preferred option: JDK 9+ Lookup.defineClass API if ClassLoader matches
|
||||
if (contextClass != null && contextClass.getClassLoader() == loader) {
|
||||
@@ -455,6 +453,7 @@ public class ReflectUtils {
|
||||
// in case of plain LinkageError (class already defined)
|
||||
// or IllegalArgumentException (class in different package):
|
||||
// fall through to traditional ClassLoader.defineClass below
|
||||
t = ex;
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new CodeGenerationException(ex);
|
||||
@@ -478,9 +477,11 @@ public class ReflectUtils {
|
||||
throw new CodeGenerationException(ex.getTargetException());
|
||||
}
|
||||
// in case of UnsupportedOperationException, fall through
|
||||
t = ex.getTargetException();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
// publicDefineClass method not available -> fall through
|
||||
t = ex;
|
||||
}
|
||||
|
||||
// Classic option: protected ClassLoader.defineClass method
|
||||
@@ -501,6 +502,7 @@ public class ReflectUtils {
|
||||
if (!ex.getClass().getName().endsWith("InaccessibleObjectException")) {
|
||||
throw new CodeGenerationException(ex);
|
||||
}
|
||||
t = ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -518,7 +520,7 @@ public class ReflectUtils {
|
||||
|
||||
// No defineClass variant available at all?
|
||||
if (c == null) {
|
||||
throw new CodeGenerationException(THROWABLE);
|
||||
throw new CodeGenerationException(t);
|
||||
}
|
||||
|
||||
// Force static initializers to run.
|
||||
|
||||
Reference in New Issue
Block a user