java.lang.reflect

Class AccessibleObject

public class AccessibleObject extends Object implements AnnotatedElement

This class is the superclass of various reflection classes, and allows sufficiently trusted code to bypass normal restrictions to do necessary things like invoke private methods outside of the class during Serialization. If you don't have a good reason to mess with this, don't try. Fortunately, there are adequate security checks before you can set a reflection object as accessible.

Since: 1.2

See Also: Field Constructor Method ReflectPermission

UNKNOWN: updated to 1.5

Constructor Summary
protected AccessibleObject()
Only the three reflection classes that extend this can create an accessible object.
Method Summary
<T extends Annotation> TgetAnnotation(Class<T> annotationClass)
Annotation[]getAnnotations()
Annotation[]getDeclaredAnnotations()
booleanisAccessible()
Return the accessibility status of this object.
booleanisAnnotationPresent(Class<? extends Annotation> annotationClass)
static voidsetAccessible(AccessibleObject[] array, boolean flag)
Convenience method to set the flag on a number of objects with a single security check.
voidsetAccessible(boolean flag)
Sets the accessibility flag for this reflection object.

Constructor Detail

AccessibleObject

protected AccessibleObject()
Only the three reflection classes that extend this can create an accessible object. This is not serializable for security reasons.

Method Detail

getAnnotation

public <T extends Annotation> T getAnnotation(Class<T> annotationClass)

getAnnotations

public Annotation[] getAnnotations()

getDeclaredAnnotations

public Annotation[] getDeclaredAnnotations()

isAccessible

public boolean isAccessible()
Return the accessibility status of this object.

Returns: true if this object bypasses security checks

isAnnotationPresent

public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)

setAccessible

public static void setAccessible(AccessibleObject[] array, boolean flag)
Convenience method to set the flag on a number of objects with a single security check. If a security manager exists, it is checked for ReflectPermission("suppressAccessChecks").

It is forbidden to set the accessibility flag to true on any constructor for java.lang.Class. This will result in a SecurityException. If the SecurityException is thrown for any of the passed AccessibleObjects, the accessibility flag will be set on AccessibleObjects in the array prior to the one which resulted in the exception.

Parameters: array the array of accessible objects flag the desired state of accessibility, true to bypass security

Throws: NullPointerException if array is null SecurityException if the request is denied

See Also: checkPermission RuntimePermission

setAccessible

public void setAccessible(boolean flag)
Sets the accessibility flag for this reflection object. If a security manager exists, it is checked for ReflectPermission("suppressAccessChecks").

It is forbidden to set the accessibility flag to true on any constructor for java.lang.Class. This will result in a SecurityException.

Parameters: flag the desired state of accessibility, true to bypass security

Throws: NullPointerException if array is null SecurityException if the request is denied

See Also: checkPermission RuntimePermission