AccessibleObject
class is the base class for Field
,
Method
, and Constructor
objects (known as reflected
objects). It provides the ability to flag a reflected object as
suppressing checks for Java language access control when it is used. This
permits sophisticated applications with sufficient privilege, such as Java
Object Serialization or other persistence mechanisms, to manipulate objects
in a manner that would normally be prohibited.
Java language access control prevents use of private members outside
their top-level class; package access members outside their package; protected members
outside their package or subclasses; and public members outside their
module unless they are declared in an exported
package and the user reads
their module. By
default, Java language access control is enforced (with one variation) when
Field
s, Method
s, or Constructor
s are used to get or
set fields, to invoke methods, or to create and initialize new instances of
classes, respectively. Every reflected object checks that the code using it
is in an appropriate class, package, or module. The check when invoked by
JNI code with no Java
class on the stack only succeeds if the member and the declaring class are
public, and the class is in a package that is exported to all modules.
The one variation from Java language access control is that the checks by reflected objects assume readability. That is, the module containing the use of a reflected object is assumed to read the module in which the underlying field, method, or constructor is declared.
Whether the checks for Java language access control can be suppressed
(and thus, whether access can be enabled) depends on whether the reflected
object corresponds to a member in an exported or open package
(see setAccessible(boolean)
).
Modifier and Type | Class and Description |
---|---|
private static class |
Modifier and Type | Field and Description |
---|---|
pack-priv volatile Object | |
pack-priv boolean | |
private static volatile boolean | |
private static volatile boolean | |
pack-priv static final ReflectionFactory |
Access | Constructor and Description |
---|---|
protected |
Modifier and Type | Method and Description |
---|---|
public final boolean | |
pack-priv final void | |
pack-priv void | checkCanSetAccessible(Class<?> caller)
If the given AccessibleObject is a |
pack-priv final void | |
private boolean | |
pack-priv static void | |
public <T extends Annotation> T | getAnnotation(Class<T>
the Class object corresponding to the
annotation type annotationClass)Implements java. |
public Annotation[] | getAnnotations()
Implements java. |
public <T extends Annotation> T[] | getAnnotationsByType(Class<T>
the Class object corresponding to the
annotation type annotationClass)Overrides default java. |
public <T extends Annotation> T | getDeclaredAnnotation(Class<T>
the Class object corresponding to the
annotation type annotationClass)Overrides default java. |
public Annotation[] | getDeclaredAnnotations()
Implements java. |
public <T extends Annotation> T[] | getDeclaredAnnotationsByType(Class<T>
the Class object corresponding to the
annotation type annotationClass)Overrides default java. |
pack-priv AccessibleObject | |
private boolean | |
private boolean | |
public boolean | Returns: the value of the object'saccessible flag
Deprecated
since 9. This method is deprecated because its name hints that it checks
if the reflected object is accessible when it actually indicates
if the checks for Java language access control are suppressed.
Get the value of the accessible flag for this reflected object.
|
public boolean | isAnnotationPresent(Class<? extends Annotation>
the Class object corresponding to the
annotation type annotationClass)Overrides default java. |
private boolean | |
private static boolean | |
public static void | setAccessible(AccessibleObject[]
the array of AccessibleObjects array, boolean the new value for the flag)accessible flag
in each objectConvenience method to set the |
public void | setAccessible(boolean
the new value for the flag)accessible flagSet the |
pack-priv boolean | |
private boolean | |
private void | |
pack-priv String | |
public final boolean | Returns: true if the accessible flag is set to true ;
false if access cannot be enabled.Set the |
pack-priv final boolean |
accessCheckCache | back to summary |
---|---|
pack-priv volatile Object accessCheckCache |
override | back to summary |
---|---|
pack-priv boolean override |
printStackPropertiesSet | back to summary |
---|---|
private static volatile boolean printStackPropertiesSet |
printStackWhenAccessFails | back to summary |
---|---|
private static volatile boolean printStackWhenAccessFails |
reflectionFactory | back to summary |
---|---|
pack-priv static final ReflectionFactory reflectionFactory
|
AccessibleObject | back to summary |
---|---|
protected AccessibleObject()
Deprecated since 17. Constructor: only used by the Java Virtual Machine.
|
canAccess | back to summary |
---|---|
public final boolean canAccess(Object obj) Test if the caller can access this reflected object. If this reflected
object corresponds to an instance method or field then this method tests
if the caller can access the given This method returns
|
checkAccess | back to summary |
---|---|
pack-priv final void checkAccess(Class<?> caller, Class<?> memberClass, Class<?> targetClass, int modifiers) throws IllegalAccessException |
checkCanSetAccessible | back to summary |
---|---|
pack-priv void checkCanSetAccessible(Class<?> caller) If the given AccessibleObject is a |
checkCanSetAccessible | back to summary |
---|---|
pack-priv final void checkCanSetAccessible(Class<?> caller, Class<?> declaringClass) |
checkCanSetAccessible | back to summary |
---|---|
private boolean checkCanSetAccessible(Class<?> caller, Class<?> declaringClass, boolean throwExceptionIfDenied) |
checkPermission | back to summary |
---|---|
pack-priv static void checkPermission() |
getAnnotation | back to summary |
---|---|
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) Implements java. Doc from java. Returns this element's annotation for the specified type if such an annotation is present, else null. Note that any annotation returned by this method is a declaration annotation. Implementation Specification The default implementation throws
|
getAnnotations | back to summary |
---|---|
public Annotation[] getAnnotations() Implements java. Doc from java. Returns annotations that are present on this element. If there are no annotations present on this element, the return value is an array of length 0. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers. Note that any annotations returned by this method are declaration annotations.
|
getAnnotationsByType | back to summary |
---|---|
public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) Overrides default java. Doc from java. Returns annotations that are associated with this element.
If there are no annotations associated with this element, the return
value is an array of length 0.
The difference between this method and Note that any annotations returned by this method are declaration annotations. Implementation Specification The default implementation throws
|
getDeclaredAnnotation | back to summary |
---|---|
public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) Overrides default java. Doc from java. Returns this element's annotation for the specified type if such an annotation is directly present, else null. This method ignores inherited annotations. (Returns null if no annotations are directly present on this element.) Note that any annotation returned by this method is a declaration annotation.
|
getDeclaredAnnotations | back to summary |
---|---|
public Annotation[] getDeclaredAnnotations() Implements java. Doc from java. Returns annotations that are directly present on this element. This method ignores inherited annotations. If there are no annotations directly present on this element, the return value is an array of length 0. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers. Note that any annotations returned by this method are declaration annotations. Implementation Specification The default implementation throws
|
getDeclaredAnnotationsByType | back to summary |
---|---|
public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) Overrides default java. Doc from java. Returns this element's annotation(s) for the specified type if
such annotations are either directly present or
indirectly present. This method ignores inherited
annotations.
If there are no specified annotations directly or indirectly
present on this element, the return value is an array of length
0.
The difference between this method and Note that any annotations returned by this method are declaration annotations.
|
getRoot | back to summary |
---|---|
pack-priv AccessibleObject getRoot() Returns the root AccessibleObject; or null if this object is the root. All subclasses override this method. |
isAccessChecked | back to summary |
---|---|
private boolean isAccessChecked(Class<?> caller, Class<?> targetClass) |
isAccessChecked | back to summary |
---|---|
private boolean isAccessChecked(Class<?> caller) |
isAccessible | back to summary |
---|---|
public boolean isAccessible()
Deprecated since 9. This method is deprecated because its name hints that it checks
if the reflected object is accessible when it actually indicates
if the checks for Java language access control are suppressed.
This method may return Get the value of the
|
isAnnotationPresent | back to summary |
---|---|
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) Overrides default java. Doc from java. Returns true if an annotation for the specified type is present on this element, else false. This method is designed primarily for convenient access to marker annotations. The truth value returned by this method is equivalent to:
|
isSubclassOf | back to summary |
---|---|
private boolean isSubclassOf(Class<?> queryClass, Class<?> ofClass) |
printStackTraceWhenAccessFails | back to summary |
---|---|
private static boolean printStackTraceWhenAccessFails() Returns true if a stack trace should be printed when access fails. |
setAccessible | back to summary |
---|---|
public static void setAccessible(AccessibleObject[] array, boolean flag) Convenience method to set the This method may be used to enable access to all reflected objects in
the array when access to each reflected object can be enabled as
specified by If there is a security manager, its
A
|
setAccessible | back to summary |
---|---|
public void setAccessible(boolean flag) Set the This method may be used by a caller in class
This method may be used by JNI code
with no caller class on the stack to enable access to a
This method cannot be used to enable access to private members, members with default (package) access, protected instance members, or protected constructors when the declaring class is in a different module to the caller and the package containing the declaring class is not open to the caller's module. This method cannot be used to enable write access to a non-modifiable final field. The following fields are non-modifiable:
The If there is a security manager, its
|
setAccessible0 | back to summary |
---|---|
pack-priv boolean setAccessible0(boolean flag) Sets the accessible flag and returns the new value |
slowVerifyAccess | back to summary |
---|---|
private boolean slowVerifyAccess(Class<?> caller, Class<?> memberClass, Class<?> targetClass, int modifiers) |
throwInaccessibleObjectException | back to summary |
---|---|
private void throwInaccessibleObjectException(Class<?> caller, Class<?> declaringClass) |
toShortString | back to summary |
---|---|
pack-priv String toShortString() Returns a short descriptive string to describe this object in log messages. |
trySetAccessible | back to summary |
---|---|
public final boolean trySetAccessible() Set the This method is a no-op if the For example, a caller can invoke
If this method is invoked by JNI code
with no caller class on the stack, the If there is a security manager, its
|
verifyAccess | back to summary |
---|---|
pack-priv final boolean verifyAccess(Class<?> caller, Class<?> memberClass, Class<?> targetClass, int modifiers) |
Modifier and Type | Field and Description |
---|---|
pack-priv final WeakReference | |
pack-priv final WeakReference |
Access | Constructor and Description |
---|---|
pack-priv |
Modifier and Type | Method and Description |
---|---|
pack-priv boolean | |
pack-priv static Object |
callerRef | back to summary |
---|---|
pack-priv final WeakReference<Class<?>> callerRef |
targetRef | back to summary |
---|---|
pack-priv final WeakReference<Class<?>> targetRef |
Cache | back to summary |
---|---|
pack-priv Cache(Class<?> caller, Class<?> target) |
isCacheFor | back to summary |
---|---|
pack-priv boolean isCacheFor(Class<?> caller, Class<?> refc) |
protectedMemberCallerCache | back to summary |
---|---|
pack-priv static Object protectedMemberCallerCache(Class<?> caller, Class<?> refc) |