|
22 | 22 | import java.lang.reflect.Method; |
23 | 23 | import java.lang.reflect.Modifier; |
24 | 24 | import java.lang.reflect.Proxy; |
25 | | -import java.security.AccessControlException; |
26 | 25 | import java.util.Arrays; |
27 | 26 | import java.util.Collection; |
28 | 27 | import java.util.Collections; |
@@ -215,7 +214,7 @@ public static Class<?> forName(String name) throws ClassNotFoundException, Linka |
215 | 214 |
|
216 | 215 | /** |
217 | 216 | * Replacement for {@code Class.forName()} that also returns Class instances |
218 | | - * for primitives (e.g."int") and array class names (e.g. "String[]"). |
| 217 | + * for primitives (e.g. "int") and array class names (e.g. "String[]"). |
219 | 218 | * Furthermore, it is also capable of resolving inner class names in Java source |
220 | 219 | * style (e.g. "java.lang.Thread.State" instead of "java.lang.Thread$State"). |
221 | 220 | * @param name the name of the Class |
@@ -397,21 +396,27 @@ public static Class<?> getUserClass(Class<?> clazz) { |
397 | 396 | */ |
398 | 397 | public static boolean isCacheSafe(Class<?> clazz, ClassLoader classLoader) { |
399 | 398 | Assert.notNull(clazz, "Class must not be null"); |
400 | | - ClassLoader target = clazz.getClassLoader(); |
401 | | - if (target == null) { |
402 | | - return true; |
403 | | - } |
404 | | - ClassLoader cur = classLoader; |
405 | | - if (cur == target) { |
406 | | - return true; |
407 | | - } |
408 | | - while (cur != null) { |
409 | | - cur = cur.getParent(); |
| 399 | + try { |
| 400 | + ClassLoader target = clazz.getClassLoader(); |
| 401 | + if (target == null) { |
| 402 | + return true; |
| 403 | + } |
| 404 | + ClassLoader cur = classLoader; |
410 | 405 | if (cur == target) { |
411 | 406 | return true; |
412 | 407 | } |
| 408 | + while (cur != null) { |
| 409 | + cur = cur.getParent(); |
| 410 | + if (cur == target) { |
| 411 | + return true; |
| 412 | + } |
| 413 | + } |
| 414 | + return false; |
| 415 | + } |
| 416 | + catch (SecurityException ex) { |
| 417 | + // Probably from the system ClassLoader - let's consider it safe. |
| 418 | + return true; |
413 | 419 | } |
414 | | - return false; |
415 | 420 | } |
416 | 421 |
|
417 | 422 |
|
@@ -800,7 +805,7 @@ public static Method getMostSpecificMethod(Method method, Class<?> targetClass) |
800 | 805 | return (specificMethod != null ? specificMethod : method); |
801 | 806 | } |
802 | 807 | } |
803 | | - catch (AccessControlException ex) { |
| 808 | + catch (SecurityException ex) { |
804 | 809 | // Security settings are disallowing reflective access; fall back to 'method' below. |
805 | 810 | } |
806 | 811 | } |
|
0 commit comments