Class AccessibleInfo
- Direct Known Subclasses:
ExecutableInfo,FieldInfo
AccessibleObject.
This class extends ElementInfo to provide common functionality for reflection elements that can be made
accessible (fields, methods, and constructors). It mirrors the AccessibleObject API, allowing private
members to be accessed via reflection.
Features:
- Accessibility control - make private members accessible
- Security exception handling - gracefully handles security exceptions
- Accessibility checking - check if an element is accessible
- Fluent API - methods return
this for method chaining
Use Cases:
- Accessing private fields, methods, or constructors
- Building frameworks that need to work with non-public members
- Testing scenarios where private members need to be accessed
Usage:
Security:
The setAccessible() method attempts to make the element accessible and quietly ignores
SecurityException if the security manager denies access. This allows code to work in
both secure and non-secure environments.
See Also:
ElementInfo- Base class for all reflection elementsFieldInfo- Field introspectionMethodInfo- Method introspectionConstructorInfo- Constructor introspection- Reflection Package
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAccessibleInfo(AccessibleObject inner, int modifiers) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturnstrue if this object is accessible.booleanAttempts to callx.setAccessible(and quietly ignores security exceptions.true )Methods inherited from class org.apache.juneau.commons.reflect.ElementInfo
ai, getModifiers, is, isAbstract, isAll, isAny, isFinal, isInterface, isNative, isNotAbstract, isNotFinal, isNotInterface, isNotNative, isNotPrivate, isNotProtected, isNotPublic, isNotStatic, isNotSynchronized, isNotTransient, isNotVolatile, isPrivate, isProtected, isPublic, isStatic, isSynchronized, isTransient, isVolatile
-
Constructor Details
-
AccessibleInfo
Constructor.- Parameters:
inner- TheAccessibleObjectbeing wrapped.
-
-
Method Details
-
isAccessible
Returnstrue if this object is accessible.This method was added in Java 9. For earlier versions, this always returns
false .Example:
// Check if accessible without security checks if (!accessibleInfo.isAccessible()) { accessibleInfo.setAccessible(); }- Returns:
true if this object is accessible,false otherwise or if not supported.
-
setAccessible
Attempts to callx.setAccessible(and quietly ignores security exceptions.true )- Returns:
true if call was successful.
-