APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.reflect

public Class Reflection

extends Object
Class Inheritance
Imports
java.lang.reflect.*, java.util.HashMap, .Map, .Objects, .Set, jdk.internal.access.JavaLangAccess, .SharedSecrets, jdk.internal.misc.VM, jdk.internal.vm.annotation.ForceInline, .IntrinsicCandidate

Common utility routines used by both java.lang and java.lang.reflect

Field Summary

Modifier and TypeField and Description
public static final Set<String>
private static volatile Map<Class<?>, Set<String>>
fieldFilterMap

Used to filter out fields and methods from certain classes from public view, where they are sensitive or they may contain VM-internal objects.

private static volatile Map<Class<?>, Set<String>>
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

the display string
accessControlStatus
(int
modifier input
modifiers
)

Returns a display string for the access control modifier status.

public static void
appendAccessControlModifiers(StringBuilder
the buffer
sb
,
int
the modifiers
modifiers
)

Adds the public/protected/private access control modifiers to a display buffer.

public static native boolean
areNestMates(Class<?> currentClass, Class<?> memberClass)

Returns true if currentClass and memberClass are nestmates - that is, if they have the same nesthost as determined by the VM.

public static void
ensureMemberAccess(Class<?>
the class performing the access
currentClass
,
Class<?>
the declaring class of the member being accessed
memberClass
,
Class<?>
the class of target object if accessing instance field or method; or the declaring class if accessing constructor; or null if accessing static field or method
targetClass
,
int
the member's access modifiers
modifiers
)

Ensures that access to a member is granted and throws IllegalAccessException if not.

public static void
ensureNativeAccess(Class<?> currentClass, Class<?> owner, String methodName, boolean jni)

private static Member[]
filter(Member[] members, Set<String> filteredNames)

public static Field[]
filterFields(Class<?> containingClass, Field[] fields)

public static Method[]
filterMethods(Class<?> containingClass, Method[] methods)

public static native Class<?>
getCallerClass()

Returns the class of the caller of the method calling this method, ignoring frames associated with java.lang.reflect.Method.invoke() and its implementation.

public static int
getClassAccessFlags(Class<?> c)

Retrieves the access flags written to the class file.

public static boolean
isCallerSensitive(Method m)

Tests if the given method is caller-sensitive and the declaring class is defined by either the bootstrap class loader or platform class loader.

private static boolean
isSameClassPackage(Class<?> c1, Class<?> c2)

Returns true if two classes in the same package.

pack-priv static boolean
isSubclassOf(Class<?> queryClass, Class<?> ofClass)

public static boolean
private static String
msgSuffix(int modifiers)

public static IllegalAccessException
newIllegalAccessException(Class<?> currentClass, Class<?> memberClass, Class<?> targetClass, int modifiers)

Returns an IllegalAccessException with an exception message based on the access that is denied.

private static IllegalAccessException
newIllegalAccessException(Class<?> memberClass, int modifiers)

Returns an IllegalAccessException with an exception message where there is no caller frame.

public static synchronized void
registerFieldsToFilter(Class<?> containingClass, Set<String> fieldNames)

private static Map<Class<?>, Set<String>>
registerFilter(Map<Class<?>, Set<String>> map, Class<?> containingClass, Set<String> names)

public static synchronized void
registerMethodsToFilter(Class<?> containingClass, Set<String> methodNames)

public static boolean

Returns:

true if access to member is granted
verifyMemberAccess
(Class<?>
the class performing the access
currentClass
,
Class<?>
the declaring class of the member being accessed
memberClass
,
Class<?>
the class of target object if accessing instance field or method; or the declaring class if accessing constructor; or null if accessing static field or method
targetClass
,
int
the member's access modifiers
modifiers
)

Verify access to a member and return true if it is granted.

public static boolean
verifyModuleAccess(Module currentModule, Class<?> memberClass)

Returns true if memberClass's module exports memberClass's package to currentModule.

public static boolean
verifyPublicMemberAccess(Class<?> memberClass, int modifiers)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALL_MEMBERSback to summary
public static final Set<String> ALL_MEMBERS
fieldFilterMapback to summary
private static volatile Map<Class<?>, Set<String>> fieldFilterMap

Used to filter out fields and methods from certain classes from public view, where they are sensitive or they may contain VM-internal objects. These Maps are updated very rarely. Rather than synchronize on each access, we use copy-on-write

methodFilterMapback to summary
private static volatile Map<Class<?>, Set<String>> methodFilterMap
WILDCARDback to summary
private static final String WILDCARD

Constructor Detail

Reflectionback to summary
public Reflection()

Method Detail

accessControlStatusback to summary
public static String accessControlStatus(int modifiers)

Returns a display string for the access control modifier status. In particular, this prints "package-private" status. Reports upon an illegal modifier input.

Parameters
modifiers:int

modifier input

Returns:String

the display string

appendAccessControlModifiersback to summary
public static void appendAccessControlModifiers(StringBuilder sb, int modifiers)

Adds the public/protected/private access control modifiers to a display buffer.

Parameters
sb:StringBuilder

the buffer

modifiers:int

the modifiers

areNestMatesback to summary
public static native boolean areNestMates(Class<?> currentClass, Class<?> memberClass)

Returns true if currentClass and memberClass are nestmates - that is, if they have the same nesthost as determined by the VM.

ensureMemberAccessback to summary
public static void ensureMemberAccess(Class<?> currentClass, Class<?> memberClass, Class<?> targetClass, int modifiers) throws IllegalAccessException

Ensures that access to a member is granted and throws IllegalAccessException if not.

Parameters
currentClass:Class<?>

the class performing the access

memberClass:Class<?>

the declaring class of the member being accessed

targetClass:Class<?>

the class of target object if accessing instance field or method; or the declaring class if accessing constructor; or null if accessing static field or method

modifiers:int

the member's access modifiers

Exceptions
IllegalAccessException:
if access to member is denied
ensureNativeAccessback to summary
public static void ensureNativeAccess(Class<?> currentClass, Class<?> owner, String methodName, boolean jni)
Annotations
@ForceInline
filterback to summary
private static Member[] filter(Member[] members, Set<String> filteredNames)
filterFieldsback to summary
public static Field[] filterFields(Class<?> containingClass, Field[] fields)
filterMethodsback to summary
public static Method[] filterMethods(Class<?> containingClass, Method[] methods)
getCallerClassback to summary
public static native Class<?> getCallerClass()

Returns the class of the caller of the method calling this method, ignoring frames associated with java.lang.reflect.Method.invoke() and its implementation.

Annotations
@CallerSensitive
@IntrinsicCandidate
getClassAccessFlagsback to summary
public static int getClassAccessFlags(Class<?> c)

Retrieves the access flags written to the class file. For inner classes these flags may differ from those returned by Class.getModifiers(), which searches the InnerClasses attribute to find the source-level access flags. This is used instead of Class.getModifiers() for run-time access checks due to compatibility reasons; see 4471811. Only the values of the low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be valid.

isCallerSensitiveback to summary
public static boolean isCallerSensitive(Method m)

Tests if the given method is caller-sensitive and the declaring class is defined by either the bootstrap class loader or platform class loader.

isSameClassPackageback to summary
private static boolean isSameClassPackage(Class<?> c1, Class<?> c2)

Returns true if two classes in the same package.

isSubclassOfback to summary
pack-priv static boolean isSubclassOf(Class<?> queryClass, Class<?> ofClass)
isTrustedFinalFieldback to summary
public static boolean isTrustedFinalField(Field field)
msgSuffixback to summary
private static String msgSuffix(int modifiers)
newIllegalAccessExceptionback to summary
public static IllegalAccessException newIllegalAccessException(Class<?> currentClass, Class<?> memberClass, Class<?> targetClass, int modifiers)

Returns an IllegalAccessException with an exception message based on the access that is denied.

newIllegalAccessExceptionback to summary
private static IllegalAccessException newIllegalAccessException(Class<?> memberClass, int modifiers)

Returns an IllegalAccessException with an exception message where there is no caller frame.

registerFieldsToFilterback to summary
public static synchronized void registerFieldsToFilter(Class<?> containingClass, Set<String> fieldNames)
registerFilterback to summary
private static Map<Class<?>, Set<String>> registerFilter(Map<Class<?>, Set<String>> map, Class<?> containingClass, Set<String> names)
registerMethodsToFilterback to summary
public static synchronized void registerMethodsToFilter(Class<?> containingClass, Set<String> methodNames)
verifyMemberAccessback to summary
public static boolean verifyMemberAccess(Class<?> currentClass, Class<?> memberClass, Class<?> targetClass, int modifiers)

Verify access to a member and return true if it is granted.

Parameters
currentClass:Class<?>

the class performing the access

memberClass:Class<?>

the declaring class of the member being accessed

targetClass:Class<?>

the class of target object if accessing instance field or method; or the declaring class if accessing constructor; or null if accessing static field or method

modifiers:int

the member's access modifiers

Returns:boolean

true if access to member is granted

verifyModuleAccessback to summary
public static boolean verifyModuleAccess(Module currentModule, Class<?> memberClass)

Returns true if memberClass's module exports memberClass's package to currentModule.

verifyPublicMemberAccessback to summary
public static boolean verifyPublicMemberAccess(Class<?> memberClass, int modifiers)