diff options
Diffstat (limited to 'libjava/java/lang/Class.java')
-rw-r--r-- | libjava/java/lang/Class.java | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/libjava/java/lang/Class.java b/libjava/java/lang/Class.java index b0151db7e2d..67805172aa0 100644 --- a/libjava/java/lang/Class.java +++ b/libjava/java/lang/Class.java @@ -51,6 +51,8 @@ import java.lang.reflect.Method; import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.security.ProtectionDomain; import java.util.ArrayList; import java.util.Arrays; @@ -60,6 +62,7 @@ import java.util.Collection; import java.lang.reflect.AnnotatedElement; import java.lang.annotation.Annotation; import java.lang.annotation.Inherited; +import java.lang.reflect.AccessibleObject; /** * A Class represents a Java type. There will never be multiple Class @@ -1004,7 +1007,9 @@ public final class Class<T> { try { - return (T[]) getMethod("values").invoke(null); + Method m = getMethod("values"); + setAccessible(m); + return (T[]) m.invoke(null); } catch (NoSuchMethodException exception) { @@ -1402,4 +1407,19 @@ public final class Class<T> * @since 1.5 */ public native boolean isMemberClass(); + + /** + * Utility method for use by classes in this package. + */ + static void setAccessible(final AccessibleObject obj) + { + AccessController.doPrivileged(new PrivilegedAction() + { + public Object run() + { + obj.setAccessible(true); + return null; + } + }); + } } |