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. 9
      spring-core/src/main/java/org/springframework/util/ClassUtils.java

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

@ -22,7 +22,6 @@ import java.lang.reflect.Constructor; @@ -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;
@ -365,6 +364,7 @@ public abstract class ClassUtils { @@ -365,6 +364,7 @@ public abstract class ClassUtils {
*/
public static boolean isCacheSafe(Class<?> clazz, ClassLoader classLoader) {
Assert.notNull(clazz, "Class must not be null");
try {
ClassLoader target = clazz.getClassLoader();
if (target == null) {
return true;
@ -381,6 +381,11 @@ public abstract class ClassUtils { @@ -381,6 +381,11 @@ public abstract class ClassUtils {
}
return false;
}
catch (SecurityException ex) {
// Probably from the system ClassLoader - let's consider it safe.
return true;
}
}
/**
@ -768,7 +773,7 @@ public abstract class ClassUtils { @@ -768,7 +773,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.
}
}

Loading…
Cancel
Save