APIdia Launch Partner
Top Description Fields Constructors Methods
sun.invoke.util

public Class VerifyAccess

extends Object
Class Inheritance
Imports
java.lang.reflect.Modifier, jdk.internal.reflect.Reflection

This class centralizes information about the JVM's linkage access control.
Author
jrose

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

whether parentClass precedes or equals childClass in class loader order
classLoaderIsAncestor
(Class<?>
a class
parentClass
,
Class<?>
another class, which may be a descendent of the first class
childClass
)

Is the class loader of parentClass identical to, or an ancestor of, the class loader of childClass?

public static boolean
ensureTypeVisible(Class<?>
the supposed type of a member or symbolic reference of refc
type
,
Class<?>
the class attempting to make the reference
refc
)

Decide if the given method type, attributed to a member or symbolic reference of a given reference class, is really visible to that class.

public static boolean
ensureTypeVisible(MethodType
the supposed type of a member or symbolic reference of refc
type
,
Class<?>
the class attempting to make the reference
refc
)

Decide if the given method type, attributed to a member or symbolic reference of a given reference class, is really visible to that class.

pack-priv static int
private static Class<?>
public static boolean
isClassAccessible(Class<?>
the symbolic reference class to which access is being checked (C)
refc
,
Class<?>
the class performing the lookup (D)
lookupClass
,
Class<?>
the class from which the lookup was teleported or null
prevLookupClass
,
int
allowed modes
allowedModes
)

Evaluate the JVM linkage rules for access to the given class on behalf of caller.

public static boolean

Returns:

true iff the accessing class can access such a member
isMemberAccessible
(Class<?>
the class used in the symbolic reference to the proposed member
refc
,
Class<?>
the class in which the proposed member is actually defined
defc
,
int
modifier flags for the proposed member
mods
,
Class<?>
the class for which the access check is being made
lookupClass
,
Class<?>
the class for which the access check is being made
prevLookupClass
,
int
allowed modes
allowedModes
)

Evaluate the JVM linkage rules for access to the given method on behalf of a caller class which proposes to perform the access.

public static boolean
pack-priv static boolean
isRelatedClass(Class<?> refc, Class<?> lookupClass)

public static boolean

Returns:

whether they are in the same module
isSameModule
(Class<?>
a class
class1
,
Class<?>
another class
class2
)

Tests if two classes are in the same module.

public static boolean

Returns:

whether they are in the same package
isSamePackage
(Class<?>
a class
class1
,
Class<?>
another class
class2
)

Test if two classes have the same class loader and package qualifier.

public static boolean

Returns:

whether they are identical or nested together
isSamePackageMember
(Class<?>
a class
class1
,
Class<?>
another class
class2
)

Test if two classes are defined as part of the same package member (top-level class).

pack-priv static boolean
isSubClass(Class<?> lookupClass, Class<?> defc)

private static boolean
loadersAreRelated(ClassLoader loader1, ClassLoader loader2, boolean loader1MustBeParent)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALL_ACCESS_MODESback to summary
private static final int ALL_ACCESS_MODES
MODULE_ALLOWEDback to summary
private static final int MODULE_ALLOWED
ORIGINAL_ALLOWEDback to summary
private static final int ORIGINAL_ALLOWED
PACKAGE_ALLOWEDback to summary
private static final int PACKAGE_ALLOWED
PACKAGE_ONLYback to summary
private static final int PACKAGE_ONLY
PROTECTED_OR_PACKAGE_ALLOWEDback to summary
private static final int PROTECTED_OR_PACKAGE_ALLOWED
UNCONDITIONAL_ALLOWEDback to summary
private static final int UNCONDITIONAL_ALLOWED

Constructor Detail

VerifyAccessback to summary
private VerifyAccess()

Method Detail

classLoaderIsAncestorback to summary
public static boolean classLoaderIsAncestor(Class<?> parentClass, Class<?> childClass)

Is the class loader of parentClass identical to, or an ancestor of, the class loader of childClass?

Parameters
parentClass:Class<?>

a class

childClass:Class<?>

another class, which may be a descendent of the first class

Returns:boolean

whether parentClass precedes or equals childClass in class loader order

ensureTypeVisibleback to summary
public static boolean ensureTypeVisible(Class<?> type, Class<?> refc)

Decide if the given method type, attributed to a member or symbolic reference of a given reference class, is really visible to that class.

Parameters
type:Class<?>

the supposed type of a member or symbolic reference of refc

refc:Class<?>

the class attempting to make the reference

ensureTypeVisibleback to summary
public static boolean ensureTypeVisible(MethodType type, Class<?> refc)

Decide if the given method type, attributed to a member or symbolic reference of a given reference class, is really visible to that class.

Parameters
type:MethodType

the supposed type of a member or symbolic reference of refc

refc:Class<?>

the class attempting to make the reference

getClassModifiersback to summary
pack-priv static int getClassModifiers(Class<?> c)
getOutermostEnclosingClassback to summary
private static Class<?> getOutermostEnclosingClass(Class<?> c)
isClassAccessibleback to summary
public static boolean isClassAccessible(Class<?> refc, Class<?> lookupClass, Class<?> prevLookupClass, int allowedModes)

Evaluate the JVM linkage rules for access to the given class on behalf of caller.

JVM Specification, 5.4.4 "Access Control"

A class or interface C is accessible to a class or interface D if and only if any of the following conditions are true:
  • C is public and in the same module as D.
  • D is in a module that reads the module containing C, C is public and in a package that is exported to the module that contains D.
  • C and D are members of the same runtime package.
Parameters
refc:Class<?>

the symbolic reference class to which access is being checked (C)

lookupClass:Class<?>

the class performing the lookup (D)

prevLookupClass:Class<?>

the class from which the lookup was teleported or null

allowedModes:int

allowed modes

isMemberAccessibleback to summary
public static boolean isMemberAccessible(Class<?> refc, Class<?> defc, int mods, Class<?> lookupClass, Class<?> prevLookupClass, int allowedModes)

Evaluate the JVM linkage rules for access to the given method on behalf of a caller class which proposes to perform the access. Return true if the caller class has privileges to invoke a method or access a field with the given properties. This requires an accessibility check of the referencing class, plus an accessibility check of the member within the class, which depends on the member's modifier flags.

The relevant properties include the defining class (defc) of the member, and its modifier flags (mods). Also relevant is the class used to make the initial symbolic reference to the member (refc). If this latter class is not distinguished, the defining class should be passed for both arguments (defc == refc).

JVM Specification, 5.4.4 "Access Control"

A field or method R is accessible to a class or interface D if and only if any of the following is true:
  • R is public.
  • R is protected and is declared in a class C, and D is either a subclass of C or C itself. Furthermore, if R is not static, then the symbolic reference to R must contain a symbolic reference to a class T, such that T is either a subclass of D, a superclass of D, or D itself.

    During verification, it was also required that, even if T is a superclass of D, the target reference of a protected instance field access or method invocation must be an instance of D or a subclass of D (4.10.1.8).

  • R is either protected or has default access (that is, neither public nor protected nor private), and is declared by a class in the same run-time package as D.
  • R is private and is declared in D by a class or interface belonging to the same nest as D.
If a referenced field or method is not accessible, access checking throws an IllegalAccessError. If an exception is thrown while attempting to determine the nest host of a class or interface, access checking fails for the same reason.
Parameters
refc:Class<?>

the class used in the symbolic reference to the proposed member

defc:Class<?>

the class in which the proposed member is actually defined

mods:int

modifier flags for the proposed member

lookupClass:Class<?>

the class for which the access check is being made

prevLookupClass:Class<?>

the class for which the access check is being made

allowedModes:int

allowed modes

Returns:boolean

true iff the accessing class can access such a member

isModuleAccessibleback to summary
public static boolean isModuleAccessible(Class<?> refc, Module m1, Module m2)
isRelatedClassback to summary
pack-priv static boolean isRelatedClass(Class<?> refc, Class<?> lookupClass)
isSameModuleback to summary
public static boolean isSameModule(Class<?> class1, Class<?> class2)

Tests if two classes are in the same module.

Parameters
class1:Class<?>

a class

class2:Class<?>

another class

Returns:boolean

whether they are in the same module

isSamePackageback to summary
public static boolean isSamePackage(Class<?> class1, Class<?> class2)

Test if two classes have the same class loader and package qualifier.

Parameters
class1:Class<?>

a class

class2:Class<?>

another class

Returns:boolean

whether they are in the same package

isSamePackageMemberback to summary
public static boolean isSamePackageMember(Class<?> class1, Class<?> class2)

Test if two classes are defined as part of the same package member (top-level class). If this is true, they can share private access with each other.

Parameters
class1:Class<?>

a class

class2:Class<?>

another class

Returns:boolean

whether they are identical or nested together

isSubClassback to summary
pack-priv static boolean isSubClass(Class<?> lookupClass, Class<?> defc)
loadersAreRelatedback to summary
private static boolean loadersAreRelated(ClassLoader loader1, ClassLoader loader2, boolean loader1MustBeParent)