diff -r 21b390daf444 -r 1d03cb35fbda emul/src/main/java/java/lang/reflect/AccessibleObject.java --- a/emul/src/main/java/java/lang/reflect/AccessibleObject.java Tue Dec 04 13:29:17 2012 +0100 +++ b/emul/src/main/java/java/lang/reflect/AccessibleObject.java Tue Dec 04 14:31:11 2012 +0100 @@ -25,9 +25,6 @@ package java.lang.reflect; -import java.security.AccessController; -import sun.reflect.Reflection; -import sun.reflect.ReflectionFactory; import java.lang.annotation.Annotation; /** @@ -57,14 +54,6 @@ public class AccessibleObject implements AnnotatedElement { /** - * The Permission object that is used to check whether a client - * has sufficient privilege to defeat Java language access - * control checks. - */ - static final private java.security.Permission ACCESS_PERMISSION = - new ReflectPermission("suppressAccessChecks"); - - /** * Convenience method to set the {@code accessible} flag for an * array of objects with a single security check (for efficiency). * @@ -91,11 +80,7 @@ */ public static void setAccessible(AccessibleObject[] array, boolean flag) throws SecurityException { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) sm.checkPermission(ACCESS_PERMISSION); - for (int i = 0; i < array.length; i++) { - setAccessible0(array[i], flag); - } + throw new SecurityException(); } /** @@ -124,23 +109,7 @@ * @see java.lang.RuntimePermission */ public void setAccessible(boolean flag) throws SecurityException { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) sm.checkPermission(ACCESS_PERMISSION); - setAccessible0(this, flag); - } - - /* Check that you aren't exposing java.lang.Class.. */ - private static void setAccessible0(AccessibleObject obj, boolean flag) - throws SecurityException - { - if (obj instanceof Constructor && flag == true) { - Constructor c = (Constructor)obj; - if (c.getDeclaringClass() == Class.class) { - throw new SecurityException("Can not make a java.lang.Class" + - " constructor accessible"); - } - } - obj.override = flag; + throw new SecurityException(); } /** @@ -165,13 +134,6 @@ // outside this package. boolean override; - // Reflection factory used by subclasses for creating field, - // method, and constructor accessors. Note that this is called - // very early in the bootstrapping process. - static final ReflectionFactory reflectionFactory = - AccessController.doPrivileged( - new sun.reflect.ReflectionFactory.GetReflectionFactoryAction()); - /** * @throws NullPointerException {@inheritDoc} * @since 1.5 @@ -202,73 +164,4 @@ public Annotation[] getDeclaredAnnotations() { throw new AssertionError("All subclasses should override this method"); } - - - // Shared access checking logic. - - // For non-public members or members in package-private classes, - // it is necessary to perform somewhat expensive security checks. - // If the security check succeeds for a given class, it will - // always succeed (it is not affected by the granting or revoking - // of permissions); we speed up the check in the common case by - // remembering the last Class for which the check succeeded. - // - // The simple security check for Constructor is to see if - // the caller has already been seen, verified, and cached. - // (See also Class.newInstance(), which uses a similar method.) - // - // A more complicated security check cache is needed for Method and Field - // The cache can be either null (empty cache), a 2-array of {caller,target}, - // or a caller (with target implicitly equal to this.clazz). - // In the 2-array case, the target is always different from the clazz. - volatile Object securityCheckCache; - - void checkAccess(Class caller, Class clazz, Object obj, int modifiers) - throws IllegalAccessException - { - if (caller == clazz) { // quick check - return; // ACCESS IS OK - } - Object cache = securityCheckCache; // read volatile - Class targetClass = clazz; - if (obj != null - && Modifier.isProtected(modifiers) - && ((targetClass = obj.getClass()) != clazz)) { - // Must match a 2-list of { caller, targetClass }. - if (cache instanceof Class[]) { - Class[] cache2 = (Class[]) cache; - if (cache2[1] == targetClass && - cache2[0] == caller) { - return; // ACCESS IS OK - } - // (Test cache[1] first since range check for [1] - // subsumes range check for [0].) - } - } else if (cache == caller) { - // Non-protected case (or obj.class == this.clazz). - return; // ACCESS IS OK - } - - // If no return, fall through to the slow path. - slowCheckMemberAccess(caller, clazz, obj, modifiers, targetClass); - } - - // Keep all this slow stuff out of line: - void slowCheckMemberAccess(Class caller, Class clazz, Object obj, int modifiers, - Class targetClass) - throws IllegalAccessException - { - Reflection.ensureMemberAccess(caller, clazz, obj, modifiers); - - // Success: Update the cache. - Object cache = ((targetClass == clazz) - ? caller - : new Class[] { caller, targetClass }); - - // Note: The two cache elements are not volatile, - // but they are effectively final. The Java memory model - // guarantees that the initializing stores for the cache - // elements will occur before the volatile write. - securityCheckCache = cache; // write volatile - } }