Browse Source

ClassUtils.isCacheSafe defensively catches SecurityException (for Google App Engine compatibility)

Issue: SPR-12002
pull/595/head
Juergen Hoeller 12 years ago
parent
commit
48fea0bafa
  1. 31
      spring-core/src/main/java/org/springframework/util/ClassUtils.java

31
spring-core/src/main/java/org/springframework/util/ClassUtils.java

@ -22,7 +22,6 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.security.AccessControlException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -365,21 +364,27 @@ public abstract class ClassUtils {
*/ */
public static boolean isCacheSafe(Class<?> clazz, ClassLoader classLoader) { public static boolean isCacheSafe(Class<?> clazz, ClassLoader classLoader) {
Assert.notNull(clazz, "Class must not be null"); Assert.notNull(clazz, "Class must not be null");
ClassLoader target = clazz.getClassLoader(); try {
if (target == null) { ClassLoader target = clazz.getClassLoader();
return true; if (target == null) {
} return true;
ClassLoader cur = classLoader; }
if (cur == target) { ClassLoader cur = classLoader;
return true;
}
while (cur != null) {
cur = cur.getParent();
if (cur == target) { if (cur == target) {
return true; 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;
} }
@ -768,7 +773,7 @@ public abstract class ClassUtils {
return (specificMethod != null ? specificMethod : method); return (specificMethod != null ? specificMethod : method);
} }
} }
catch (AccessControlException ex) { catch (SecurityException ex) {
// Security settings are disallowing reflective access; fall back to 'method' below. // Security settings are disallowing reflective access; fall back to 'method' below.
} }
} }

Loading…
Cancel
Save