ClassUtils.isCacheSafe defensively catches SecurityException (for Google App Engine compatibility)
Issue: SPR-12002
(cherry picked from commit 48fea0b)
This commit is contained in:
@@ -22,7 +22,6 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.security.AccessControlException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -215,7 +214,7 @@ public abstract class ClassUtils {
|
||||
|
||||
/**
|
||||
* Replacement for {@code Class.forName()} that also returns Class instances
|
||||
* for primitives (e.g."int") and array class names (e.g. "String[]").
|
||||
* for primitives (e.g. "int") and array class names (e.g. "String[]").
|
||||
* Furthermore, it is also capable of resolving inner class names in Java source
|
||||
* style (e.g. "java.lang.Thread.State" instead of "java.lang.Thread$State").
|
||||
* @param name the name of the Class
|
||||
@@ -397,21 +396,27 @@ public abstract class ClassUtils {
|
||||
*/
|
||||
public static boolean isCacheSafe(Class<?> clazz, ClassLoader classLoader) {
|
||||
Assert.notNull(clazz, "Class must not be null");
|
||||
ClassLoader target = clazz.getClassLoader();
|
||||
if (target == null) {
|
||||
return true;
|
||||
}
|
||||
ClassLoader cur = classLoader;
|
||||
if (cur == target) {
|
||||
return true;
|
||||
}
|
||||
while (cur != null) {
|
||||
cur = cur.getParent();
|
||||
try {
|
||||
ClassLoader target = clazz.getClassLoader();
|
||||
if (target == null) {
|
||||
return true;
|
||||
}
|
||||
ClassLoader cur = classLoader;
|
||||
if (cur == target) {
|
||||
return true;
|
||||
}
|
||||
while (cur != null) {
|
||||
cur = cur.getParent();
|
||||
if (cur == target) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (SecurityException ex) {
|
||||
// Probably from the system ClassLoader - let's consider it safe.
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -800,7 +805,7 @@ public abstract class ClassUtils {
|
||||
return (specificMethod != null ? specificMethod : method);
|
||||
}
|
||||
}
|
||||
catch (AccessControlException ex) {
|
||||
catch (SecurityException ex) {
|
||||
// Security settings are disallowing reflective access; fall back to 'method' below.
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user