Top Description Inners Fields Constructors Methods
java.lang.reflect

public Class Proxy

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.lang.invoke.MethodHandle, .MethodHandles, .MethodType, .WrongMethodTypeException, java.lang.module.ModuleDescriptor, java.security.AccessController, .PrivilegedAction, java.util.ArrayDeque, .Arrays, .Collections, .Deque, .HashMap, .HashSet, .IdentityHashMap, .List, .Map, .Objects, .Set, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.atomic.AtomicInteger, .AtomicLong, java.util.function.BooleanSupplier, jdk.internal.access.JavaLangAccess, .SharedSecrets, jdk.internal.module.Modules, jdk.internal.misc.VM, jdk.internal.reflect.CallerSensitive, .Reflection, jdk.internal.loader.ClassLoaderValue, jdk.internal.vm.annotation.Stable, sun.reflect.misc.ReflectUtil, sun.security.action.GetPropertyAction, sun.security.util.SecurityConstants

Proxy provides static methods for creating objects that act like instances of interfaces but allow for customized method invocation. To create a proxy instance for some interface Foo:
InvocationHandler handler = new MyInvocationHandler(...);
    Foo f = (Foo) Proxy.newProxyInstance(Foo.class.getClassLoader(),
                                         new Class<?>[] { Foo.class },
                                         handler);

A proxy class is a class created at runtime that implements a specified list of interfaces, known as proxy interfaces. A proxy instance is an instance of a proxy class. Each proxy instance has an associated invocation handler object, which implements the interface InvocationHandler. A method invocation on a proxy instance through one of its proxy interfaces will be dispatched to the invoke method of the instance's invocation handler, passing the proxy instance, a java.lang.reflect.Method object identifying the method that was invoked, and an array of type Object containing the arguments. The invocation handler processes the encoded method invocation as appropriate and the result that it returns will be returned as the result of the method invocation on the proxy instance.

A proxy class has the following properties:

A proxy instance has the following properties:

Package and Module Membership of Proxy Class

The package and module to which a proxy class belongs are chosen such that the accessibility of the proxy class is in line with the accessibility of the proxy interfaces. Specifically, the package and the module membership of a proxy class defined via the Proxy#getProxyClass(ClassLoader, Class[]) or Proxy#newProxyInstance(ClassLoader, Class[], InvocationHandler) methods is specified as follows:
  1. If all the proxy interfaces are in exported or open packages:
    1. if all the proxy interfaces are public, then the proxy class is public in an unconditionally exported but non-open package. The name of the package and the module are unspecified.
    2. if at least one of all the proxy interfaces is non-public, then the proxy class is non-public in the package and module of the non-public interfaces. All the non-public interfaces must be in the same package and module; otherwise, proxying them is not possible.
  2. If at least one proxy interface is in a package that is non-exported and non-open:
    1. if all the proxy interfaces are public, then the proxy class is public in a non-exported, non-open package of dynamic module. The names of the package and the module are unspecified.
    2. if at least one of all the proxy interfaces is non-public, then the proxy class is non-public in the package and module of the non-public interfaces. All the non-public interfaces must be in the same package and module; otherwise, proxying them is not possible.

Note that if proxy interfaces with a mix of accessibilities -- for example, an exported public interface and a non-exported non-public interface -- are proxied by the same instance, then the proxy class's accessibility is governed by the least accessible proxy interface.

Note that it is possible for arbitrary code to obtain access to a proxy class in an open package with setAccessible, whereas a proxy class in a non-open package is never accessible to code outside the module of the proxy class.

Throughout this specification, a "non-exported package" refers to a package that is not exported to all modules, and a "non-open package" refers to a package that is not open to all modules. Specifically, these terms refer to a package that either is not exported/open by its containing module or is exported/open in a qualified fashion by its containing module.

Dynamic Modules

A dynamic module is a named module generated at runtime. A proxy class defined in a dynamic module is encapsulated and not accessible to any module. Calling Constructor#newInstance(Object...) on a proxy class in a dynamic module will throw IllegalAccessException; Proxy.newProxyInstance method should be used instead.

A dynamic module can read the modules of all of the superinterfaces of a proxy class and the modules of the classes and interfaces referenced by all public method signatures of a proxy class. If a superinterface or a referenced class or interface, say T, is in a non-exported package, the module of T is updated to export the package of T to the dynamic module.

Methods Duplicated in Multiple Proxy Interfaces

When two or more proxy interfaces contain a method with the same name and parameter signature, the order of the proxy class's interfaces becomes significant. When such a duplicate method is invoked on a proxy instance, the Method object passed to the invocation handler will not necessarily be the one whose declaring class is assignable from the reference type of the interface that the proxy's method was invoked through. This limitation exists because the corresponding method implementation in the generated proxy class cannot determine which interface it was invoked through. Therefore, when a duplicate method is invoked on a proxy instance, the Method object for the method in the foremost interface that contains the method (either directly or inherited through a superinterface) in the proxy class's list of interfaces is passed to the invocation handler's invoke method, regardless of the reference type through which the method invocation occurred.

If a proxy interface contains a method with the same name and parameter signature as the hashCode, equals, or toString methods of java.lang.Object, when such a method is invoked on a proxy instance, the Method object passed to the invocation handler will have java.lang.Object as its declaring class. In other words, the public, non-final methods of java.lang.Object logically precede all of the proxy interfaces for the determination of which Method object to pass to the invocation handler.

Note also that when a duplicate method is dispatched to an invocation handler, the invoke method may only throw checked exception types that are assignable to one of the exception types in the throws clause of the method in all of the proxy interfaces that it can be invoked through. If the invoke method throws a checked exception that is not assignable to any of the exception types declared by the method in one of the proxy interfaces that it can be invoked through, then an unchecked UndeclaredThrowableException will be thrown by the invocation on the proxy instance. This restriction means that not all of the exception types returned by invoking getExceptionTypes on the Method object passed to the invoke method can necessarily be thrown successfully by the invoke method.

Author
Peter Jones
Since
1.3
See Also
InvocationHandler

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
Proxy.InvocationException

Internal exception type to wrap the exception thrown by the default method so that it can distinguish CCE and NPE thrown due to the arguments incompatible with the method signature.

private static class
Proxy.ProxyBuilder

Builder for a proxy class.

Field Summary

Modifier and TypeField and Description
private static final Class<?>[]
constructorParams

parameter types of a proxy class constructor

private static final ClassValue<ConcurrentHashMap<Method, MethodHandle>>
DEFAULT_METHODS_MAP

A cache of Method -> MethodHandle for default methods.

pack-priv static final Object[]
protected InvocationHandler
h

the invocation handler for this proxy instance.

private static final String
private static final ClassLoaderValue<Constructor<?>>
proxyCache

a cache of proxy constructors with accessible flag already set

private static final long

Constructor Summary

AccessConstructor and Description
private
Proxy()

Prohibits instantiation.

protected
Proxy(InvocationHandler
the invocation handler for this proxy instance
h
)

Constructs a new Proxy instance from a subclass (typically, a dynamic proxy class) with the specified value for its invocation handler.

Method Summary

Modifier and TypeMethod and Description
private static void
checkNewProxyPermission(Class<?> caller, Class<?> proxyClass)

private static void
checkProxyAccess(Class<?> caller, ClassLoader loader, Class<?>... interfaces)

pack-priv static MethodHandle
defaultMethodHandle(Class<? extends Proxy> proxyClass, Method method)

private static ConcurrentHashMap<Method, MethodHandle>
defaultMethodMap(Class<?> proxyClass)

private static Class<?>
findProxyInterfaceOrElseThrow(Class<?> proxyClass, Method method)

Finds the first proxy interface that declares the given method directly or indirectly.

public static InvocationHandler

Returns:

the invocation handler for the proxy instance
getInvocationHandler
(Object
the proxy instance to return the invocation handler for
proxy
)

Returns the invocation handler for the specified proxy instance.

private static ClassLoader
getLoader(Module m)

Returns the class loader for the given module.

public static Class<?>

Returns:

a proxy class that is defined in the specified class loader and that implements the specified interfaces
getProxyClass
(ClassLoader
the class loader to define the proxy class
loader
,
Class<?>...
the list of interfaces for the proxy class to implement
interfaces
)
Deprecated Proxy classes generated in a named module are encapsulated and not accessible to code outside its module.

Returns the java.lang.Class object for a proxy class given a class loader and an array of interfaces.

private static Constructor<?>

Returns:

a Constructor of the proxy class taking single InvocationHandler parameter
getProxyConstructor
(Class<?>
passed from a public-facing @CallerSensitive method if SecurityManager is set or null if there's no SecurityManager
caller
,
ClassLoader
the class loader to define the proxy class
loader
,
Class<?>...
the list of interfaces for the proxy class to implement
interfaces
)

Returns the Constructor object of a proxy class that takes a single argument of type InvocationHandler, given a class loader and an array of interfaces.

pack-priv static Object
invokeDefault(Object proxy, Method method, Object[] args, Class<?> caller)

public static boolean

Returns:

true if the class is a proxy class and false otherwise
isProxyClass
(Class<?>
the class to test
cl
)

Returns true if the given class is a proxy class.

public static Object

Returns:

a proxy instance with the specified invocation handler of a proxy class that is defined by the specified class loader and that implements the specified interfaces
newProxyInstance
(ClassLoader
the class loader to define the proxy class
loader
,
Class<?>[]
the list of interfaces for the proxy class to implement
interfaces
,
InvocationHandler
the invocation handler to dispatch method invocations to
h
)

Returns a proxy instance for the specified interfaces that dispatches method invocations to the specified invocation handler.

private static Object
private static MethodHandles.Lookup

Returns:

a lookup for proxy class of this proxy instance
proxyClassLookup
(MethodHandles.Lookup caller, Class<?> proxyClass)

This method invokes the proxy's proxyClassLookup method to get a Lookup on the proxy class.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

constructorParamsback to summary
private static final Class<?>[] constructorParams

parameter types of a proxy class constructor

DEFAULT_METHODS_MAPback to summary
private static final ClassValue<ConcurrentHashMap<Method, MethodHandle>> DEFAULT_METHODS_MAP

A cache of Method -> MethodHandle for default methods.

EMPTY_ARGSback to summary
pack-priv static final Object[] EMPTY_ARGS
hback to summary
protected InvocationHandler h

the invocation handler for this proxy instance.

Annotations
@SuppressWarnings:serial
PROXY_PACKAGE_PREFIXback to summary
private static final String PROXY_PACKAGE_PREFIX
proxyCacheback to summary
private static final ClassLoaderValue<Constructor<?>> proxyCache

a cache of proxy constructors with accessible flag already set

serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@Serial

Constructor Detail

Proxyback to summary
private Proxy()

Prohibits instantiation.

Proxyback to summary
protected Proxy(InvocationHandler h)

Constructs a new Proxy instance from a subclass (typically, a dynamic proxy class) with the specified value for its invocation handler.

Parameters
h:InvocationHandler

the invocation handler for this proxy instance

Exceptions
NullPointerException:
if the given invocation handler, h, is null.

Method Detail

checkNewProxyPermissionback to summary
private static void checkNewProxyPermission(Class<?> caller, Class<?> proxyClass)
checkProxyAccessback to summary
private static void checkProxyAccess(Class<?> caller, ClassLoader loader, Class<?>... interfaces)
defaultMethodHandleback to summary
pack-priv static MethodHandle defaultMethodHandle(Class<? extends Proxy> proxyClass, Method method)
defaultMethodMapback to summary
private static ConcurrentHashMap<Method, MethodHandle> defaultMethodMap(Class<?> proxyClass)
findProxyInterfaceOrElseThrowback to summary
private static Class<?> findProxyInterfaceOrElseThrow(Class<?> proxyClass, Method method)

Finds the first proxy interface that declares the given method directly or indirectly.

Exceptions
IllegalArgumentException:
if not found
getInvocationHandlerback to summary
public static InvocationHandler getInvocationHandler(Object proxy) throws IllegalArgumentException

Returns the invocation handler for the specified proxy instance.

Parameters
proxy:Object

the proxy instance to return the invocation handler for

Returns:InvocationHandler

the invocation handler for the proxy instance

Annotations
@SuppressWarnings:removal
@CallerSensitive
Exceptions
IllegalArgumentException:
if the argument is not a proxy instance
SecurityException:
if a security manager, s, is present and the caller's class loader is not the same as or an ancestor of the class loader for the invocation handler and invocation of s.checkPackageAccess() denies access to the invocation handler's class.
getLoaderback to summary
private static ClassLoader getLoader(Module m)

Returns the class loader for the given module.

Annotations
@SuppressWarnings:removal
getProxyClassback to summary
public static Class<?> getProxyClass(ClassLoader loader, Class<?>... interfaces) throws IllegalArgumentException

Deprecated

Proxy classes generated in a named module are encapsulated and not accessible to code outside its module. Constructor.newInstance will throw IllegalAccessException when it is called on an inaccessible proxy class. Use newProxyInstance(ClassLoader, Class[], InvocationHandler) to create a proxy instance instead.

Returns the java.lang.Class object for a proxy class given a class loader and an array of interfaces. The proxy class will be defined by the specified class loader and will implement all of the supplied interfaces. If any of the given interfaces is non-public, the proxy class will be non-public. If a proxy class for the same permutation of interfaces has already been defined by the class loader, then the existing proxy class will be returned; otherwise, a proxy class for those interfaces will be generated dynamically and defined by the class loader.

Parameters
loader:ClassLoader

the class loader to define the proxy class

interfaces:Class<?>[]

the list of interfaces for the proxy class to implement

Returns:Class<?>

a proxy class that is defined in the specified class loader and that implements the specified interfaces

Annotations
@Deprecated
@CallerSensitive
Exceptions
IllegalArgumentException:
if any of the restrictions on the parameters are violated
SecurityException:
if a security manager, s, is present and any of the following conditions is met:
  • the given loader is null and the caller's class loader is not null and the invocation of s.checkPermission with RuntimePermission("getClassLoader") permission denies access.
  • for each proxy interface, intf, the caller's class loader is not the same as or an ancestor of the class loader for intf and invocation of s.checkPackageAccess() denies access to intf.
NullPointerException:
if the interfaces array argument or any of its elements are null
See Also
Package and Module Membership of Proxy Class
getProxyConstructorback to summary
private static Constructor<?> getProxyConstructor(Class<?> caller, ClassLoader loader, Class<?>... interfaces)

Returns the Constructor object of a proxy class that takes a single argument of type InvocationHandler, given a class loader and an array of interfaces. The returned constructor will have the accessible flag already set.

Parameters
caller:Class<?>

passed from a public-facing @CallerSensitive method if SecurityManager is set or null if there's no SecurityManager

loader:ClassLoader

the class loader to define the proxy class

interfaces:Class<?>[]

the list of interfaces for the proxy class to implement

Returns:Constructor<?>

a Constructor of the proxy class taking single InvocationHandler parameter

invokeDefaultback to summary
pack-priv static Object invokeDefault(Object proxy, Method method, Object[] args, Class<?> caller) throws Throwable
isProxyClassback to summary
public static boolean isProxyClass(Class<?> cl)

Returns true if the given class is a proxy class.

Implementation Note

The reliability of this method is important for the ability to use it to make security decisions, so its implementation should not just test if the class in question extends Proxy.

Parameters
cl:Class<?>

the class to test

Returns:boolean

true if the class is a proxy class and false otherwise

Exceptions
NullPointerException:
if cl is null
newProxyInstanceback to summary
public static Object newProxyInstance(ClassLoader loader, Class<?>[] interfaces, InvocationHandler h)

Returns a proxy instance for the specified interfaces that dispatches method invocations to the specified invocation handler.

IllegalArgumentException will be thrown if any of the following restrictions is violated:

  • All of Class objects in the given interfaces array must represent non-hidden and non-sealed interfaces, not classes or primitive types.
  • No two elements in the interfaces array may refer to identical Class objects.
  • All of the interface types must be visible by name through the specified class loader. In other words, for class loader cl and every interface i, the following expression must be true:

    Class.forName(i.getName(), false, cl) == i

  • All of the types referenced by all public method signatures of the specified interfaces and those inherited by their superinterfaces must be visible by name through the specified class loader.
  • All non-public interfaces must be in the same package and module, defined by the specified class loader and the module of the non-public interfaces can access all of the interface types; otherwise, it would not be possible for the proxy class to implement all of the interfaces, regardless of what package it is defined in.
  • For any set of member methods of the specified interfaces that have the same signature:
    • If the return type of any of the methods is a primitive type or void, then all of the methods must have that same return type.
    • Otherwise, one of the methods must have a return type that is assignable to all of the return types of the rest of the methods.
  • The resulting proxy class must not exceed any limits imposed on classes by the virtual machine. For example, the VM may limit the number of interfaces that a class may implement to 65535; in that case, the size of the interfaces array must not exceed 65535.

Note that the order of the specified proxy interfaces is significant: two requests for a proxy class with the same combination of interfaces but in a different order will result in two distinct proxy classes.

Parameters
loader:ClassLoader

the class loader to define the proxy class

interfaces:Class<?>[]

the list of interfaces for the proxy class to implement

h:InvocationHandler

the invocation handler to dispatch method invocations to

Returns:Object

a proxy instance with the specified invocation handler of a proxy class that is defined by the specified class loader and that implements the specified interfaces

Annotations
@CallerSensitive
Exceptions
IllegalArgumentException:
if any of the restrictions on the parameters are violated
SecurityException:
if a security manager, s, is present and any of the following conditions is met:
  • the given loader is null and the caller's class loader is not null and the invocation of s.checkPermission with RuntimePermission("getClassLoader") permission denies access;
  • for each proxy interface, intf, the caller's class loader is not the same as or an ancestor of the class loader for intf and invocation of s.checkPackageAccess() denies access to intf;
  • any of the given proxy interfaces is non-public and the caller class is not in the same runtime package as the non-public interface and the invocation of s.checkPermission with ReflectPermission("newProxyInPackage.{package name}") permission denies access.
NullPointerException:
if the interfaces array argument or any of its elements are null, or if the invocation handler, h, is null
See Also
Package and Module Membership of Proxy Class
newProxyInstanceback to summary
private static Object newProxyInstance(Class<?> caller, Constructor<?> cons, InvocationHandler h)
proxyClassLookupback to summary
private static MethodHandles.Lookup proxyClassLookup(MethodHandles.Lookup caller, Class<?> proxyClass)

This method invokes the proxy's proxyClassLookup method to get a Lookup on the proxy class.

Returns:MethodHandles.Lookup

a lookup for proxy class of this proxy instance

Annotations
@SuppressWarnings:removal
java.lang.reflect back to summary

pack-priv Class Proxy.InvocationException

extends ReflectiveOperationException
Class Inheritance

Internal exception type to wrap the exception thrown by the default method so that it can distinguish CCE and NPE thrown due to the arguments incompatible with the method signature.

Field Summary

Modifier and TypeField and Description
private static final long
pack-priv static MethodHandle

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static Object
wrap(Throwable cause)

Wraps given cause with InvocationException and throws it.

pack-priv static MethodHandle

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.lang.ReflectiveOperationException.serialVersionUID.

Annotations
@Serial
wrapMethodHandleback to summary
pack-priv static MethodHandle wrapMethodHandle
Annotations
@Stable

Constructor Detail

InvocationExceptionback to summary
pack-priv InvocationException(Throwable cause)

Method Detail

wrapback to summary
pack-priv static Object wrap(Throwable cause) throws InvocationException

Wraps given cause with InvocationException and throws it.

wrapMHback to summary
pack-priv static MethodHandle wrapMH()
java.lang.reflect back to summary

private final Class Proxy.ProxyBuilder

extends Object
Class Inheritance

Builder for a proxy class. If the module is not specified in this ProxyBuilder constructor, it will map from the given loader and interfaces to the module in which the proxy class will be defined.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record

Field Summary

Modifier and TypeField and Description
private final Proxy.ProxyBuilder.ProxyClassContext
private static final AtomicInteger
private static final String
private static final ClassLoaderValue<Module>
private final List<Class<?>>
private static final JavaLangAccess
private static final AtomicLong
private static final String
private static final ClassLoaderValue<Boolean>

Constructor Summary

AccessConstructor and Description
pack-priv
ProxyBuilder(ClassLoader loader, List<Class<?>> interfaces)

pack-priv
ProxyBuilder(ClassLoader loader, Class<?> intf)

Method Summary

Modifier and TypeMethod and Description
private static void
addElementType(HashSet<Class<?>> types, Class<?> cls)

private static void
addElementTypes(HashSet<Class<?>> types, Class<?>... classes)

pack-priv Constructor<?>
build()

Generate a proxy class and return its proxy Constructor with accessible flag already set.

private static Class<?>
private static void
ensureAccess(Module target, Class<?> c)

private static void
private static Module
private static Class<?>
private static boolean
private static boolean
private static boolean
private static boolean
pack-priv static boolean
isProxyClass(Class<?> c)

Test if given class is a class defined by defineProxyClass(ProxyClassContext, List)

private static Proxy.ProxyBuilder.ProxyClassContext
proxyClassContext(ClassLoader loader, List<Class<?>> interfaces, Set<Class<?>> refTypes)

Returns the context for the generated proxy class, including the module and the package it belongs to and whether it is package-private.

private static Set<Class<?>>
referencedTypes(ClassLoader loader, List<Class<?>> interfaces)

private static String
pack-priv static void
trace(String cn, Module module, ClassLoader loader, List<Class<?>> interfaces)

private static void
validateProxyInterfaces(ClassLoader loader, List<Class<?>> interfaces, Set<Class<?>> refTypes)

Validate the given proxy interfaces and the given referenced types are visible to the defining loader.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextback to summary
private final Proxy.ProxyBuilder.ProxyClassContext context
counterback to summary
private static final AtomicInteger counter
DEBUGback to summary
private static final String DEBUG
dynProxyModulesback to summary
private static final ClassLoaderValue<Module> dynProxyModules
interfacesback to summary
private final List<Class<?>> interfaces
JLAback to summary
private static final JavaLangAccess JLA
nextUniqueNumberback to summary
private static final AtomicLong nextUniqueNumber
proxyClassNamePrefixback to summary
private static final String proxyClassNamePrefix
reverseProxyCacheback to summary
private static final ClassLoaderValue<Boolean> reverseProxyCache

Constructor Detail

ProxyBuilderback to summary
pack-priv ProxyBuilder(ClassLoader loader, List<Class<?>> interfaces)
ProxyBuilderback to summary
pack-priv ProxyBuilder(ClassLoader loader, Class<?> intf)

Method Detail

addElementTypeback to summary
private static void addElementType(HashSet<Class<?>> types, Class<?> cls)
addElementTypesback to summary
private static void addElementTypes(HashSet<Class<?>> types, Class<?>... classes)
buildback to summary
pack-priv Constructor<?> build()

Generate a proxy class and return its proxy Constructor with accessible flag already set. If the target module does not have access to any interface types, IllegalAccessError will be thrown by the VM at defineClass time. Must call the checkProxyAccess method to perform permission checks before calling this.

Annotations
@SuppressWarnings:removal
defineProxyClassback to summary
private static Class<?> defineProxyClass(Proxy.ProxyBuilder.ProxyClassContext context, List<Class<?>> interfaces)
ensureAccessback to summary
private static void ensureAccess(Module target, Class<?> c)
ensureVisibleback to summary
private static void ensureVisible(ClassLoader ld, Class<?> c)
getDynamicModuleback to summary
private static Module getDynamicModule(ClassLoader loader)
getElementTypeback to summary
private static Class<?> getElementType(Class<?> type)
isDebugback to summary
private static boolean isDebug()
isDebugback to summary
private static boolean isDebug(String flag)
isExportedTypeback to summary
private static boolean isExportedType(Class<?> c)
isPackagePrivateTypeback to summary
private static boolean isPackagePrivateType(Class<?> c)
isProxyClassback to summary
pack-priv static boolean isProxyClass(Class<?> c)

Test if given class is a class defined by defineProxyClass(ProxyClassContext, List)

proxyClassContextback to summary
private static Proxy.ProxyBuilder.ProxyClassContext proxyClassContext(ClassLoader loader, List<Class<?>> interfaces, Set<Class<?>> refTypes)

Returns the context for the generated proxy class, including the module and the package it belongs to and whether it is package-private. If any of proxy interface is package-private, then the proxy class is in the same package and module as the package-private interface. If all proxy interfaces are public and in exported packages, then the proxy class is in a dynamic module in an unconditionally exported package. If all proxy interfaces are public and at least one in a non-exported package, then the proxy class is in a dynamic module in a non-exported package. The package of proxy class is open to java.base for deep reflective access. Reads edge and qualified exports are added for dynamic module to access.

referencedTypesback to summary
private static Set<Class<?>> referencedTypes(ClassLoader loader, List<Class<?>> interfaces)
toDetailsback to summary
private static String toDetails(Class<?> c)
traceback to summary
pack-priv static void trace(String cn, Module module, ClassLoader loader, List<Class<?>> interfaces)
validateProxyInterfacesback to summary
private static void validateProxyInterfaces(ClassLoader loader, List<Class<?>> interfaces, Set<Class<?>> refTypes)

Validate the given proxy interfaces and the given referenced types are visible to the defining loader.

Exceptions
IllegalArgumentException:
if it violates the restrictions specified in Proxy#newProxyInstance
java.lang.reflect back to summary

private final Record Proxy.ProxyBuilder.ProxyClassContext

extends Record
Class Inheritance
Record Components
module:Module
packageName:String
accessFlags:int 

Field Summary

Modifier and TypeField and Description
private final int
accessFlags

Record Component accessed by accessFlags().

private final Module
module

Record Component accessed by module().

private final String
packageName

Record Component accessed by packageName().

Constructor Summary

AccessConstructor and Description
private
ProxyClassContext(Module module, String packageName, int accessFlags)

Method Summary

Modifier and TypeMethod and Description
public int
accessFlags()

Record Component getter of accessFlags.

public final boolean
equals(Object
the reference object with which to compare.
o
)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public Module
module()

Record Component getter of module.

public String
packageName()

Record Component getter of packageName.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

accessFlagsback to summary
private final int accessFlags

Record Component accessed by accessFlags().

moduleback to summary
private final Module module

Record Component accessed by module().

packageNameback to summary
private final String packageName

Record Component accessed by packageName().

Constructor Detail

ProxyClassContextback to summary
private ProxyClassContext(Module module, String packageName, int accessFlags)

Method Detail

accessFlagsback to summary
public int accessFlags()

Record Component getter of accessFlags.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this record is equal to the argument; false otherwise.

hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

Returns:int

a hash code value for this record.

moduleback to summary
public Module module()

Record Component getter of module.

packageNameback to summary
public String packageName()

Record Component getter of packageName.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

Returns:String

a string representation of the object.