Top Description Inners Fields Constructors Methods
net.bytebuddy.utility.dispatcher

public Class JavaDispatcher<T>

extends Object
implements PrivilegedAction<T>
Class Inheritance
All Implemented Interfaces
java.security.PrivilegedAction
Annotations
@Enhance
Type Parameters
<T>
The resolved type.
Imports
edu.umd.cs.findbugs.annotations.SuppressFBWarnings, net.bytebuddy.ClassFileVersion, net.bytebuddy.build.AccessControllerPlugin, .HashCodeAndEqualsPlugin, net.bytebuddy.description.method.MethodDescription, net.bytebuddy.dynamic.scaffold.TypeWriter, net.bytebuddy.utility.GraalImageCode, .Invoker, .MethodComparator, net.bytebuddy.utility.nullability.MaybeNull, net.bytebuddy.utility.privilege.GetSystemPropertyAction, net.bytebuddy.jar.asm.ClassWriter, .MethodVisitor, .Opcodes, .Type, java.io.File, .FileOutputStream, .OutputStream, java.lang.annotation.*, java.lang.reflect.*, java.security.Permission, .PrivilegedAction, java.util.HashMap, .LinkedHashMap, .Map

A dispatcher for creating a proxy that invokes methods of a type that is possibly unknown on the current VM. Dispatchers do not use any of Byte Buddy's regular infrastructure, to avoid bootstrapping issues as these dispatchers are used by Byte Buddy itself.

By default, this dispatcher uses the Java Proxy for creating dispatchers. By setting net.bytebuddy.generate to true, Byte Buddy can generate proxies manually as byte code to mostly avoid reflection and boxing of arguments as arrays.

If a security manager is active, the net.bytebuddy.createJavaDispatcher runtime permission is required. Any dispatching will be executed from a separate class loader and an unnamed module but with the java.security.ProtectionDomain of the JavaDispatcher class. It is not permitted to invoke methods of the java.security.AccessController class or to resolve a java.lang.invoke.MethodHandle$Lookup.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static @interface
JavaDispatcher.Container

Indicates that the method is supposed to return an array of the proxied type.

public static @interface
JavaDispatcher.Defaults

Indicates that a method is supposed to return a default value if a method or type could not be resolved.

private static class
JavaDispatcher.DirectInvoker

An Invoker that uses Byte Buddy's invocation context to use if dynamic class loading is not supported, for example on Android, and that do not use secured contexts, where this security measure is obsolete to begin with.

protected static interface
JavaDispatcher.Dispatcher

A dispatcher for handling a proxied method.

protected static class
JavaDispatcher.DynamicClassLoader

A class loader for loading synthetic classes for implementing a JavaDispatcher.

public static @interface
JavaDispatcher.Instance

Indicates that a method is supposed to perform an instance check.

private static class
JavaDispatcher.InvokerCreationAction

A privileged action for creating an Invoker.

public static @interface
JavaDispatcher.IsConstructor

Indicates that a proxied method is a constructor.

public static @interface
JavaDispatcher.IsStatic

Indicates that a proxied method is static.

public static @interface
JavaDispatcher.Proxied

Indicates a proxied type's name.

protected static class
JavaDispatcher.ProxiedInvocationHandler

An invocation handler that invokes given dispatchers.

Field Summary

Modifier and TypeField and Description
private final ClassLoader
classLoader

The class loader to resolve the proxied type from or null if the bootstrap loader should be used.

private static final boolean
GENERATE

If true, dispatcher classes will be generated natively and not by using a Proxy.

private final boolean
generate

true if a proxy class should be manually generated.

public static final String
GENERATE_PROPERTY

A property to determine, that if true, dispatcher classes will be generated natively and not by using a Proxy.

private static final Invoker
INVOKER

Contains an invoker that makes sure that reflective dispatchers make invocations from an isolated ClassLoader and not from within Byte Buddy's context.

private final Class<T>
proxy

The proxy type.

private static final JavaDispatcher.DynamicClassLoader.Resolver
RESOLVER

A resolver to assure that a type's package and module are exported to the created class loader.

Constructor Summary

AccessConstructor and Description
protected
JavaDispatcher(Class<T>
The proxy type.
proxy
,
ClassLoader
The class loader to resolve the proxied type from or null if the bootstrap loader should be used.
classLoader
,
boolean
true if a proxy class should be manually generated.
generate
)

Creates a new dispatcher.

Method Summary

Modifier and TypeMethod and Description
private static <
The type of the action's resolved value.
T
>
T

Returns:

The action's resolved value.
doPrivileged
(PrivilegedAction<T>
The action to execute from a privileged context.
action
)

A proxy for java.security.AccessController#doPrivileged that is activated if available.

public static <
The resolved type.
T
>
PrivilegedAction<T>

Returns:

An action for creating an appropriate dispatcher.
of
(Class<T>
The type for which a dispatcher should be resolved.
type
)

Resolves an action for creating a dispatcher for the provided type where the proxied type is resolved from the bootstrap loader.

protected static <
The resolved type.
T
>
PrivilegedAction<T>

Returns:

An action for creating an appropriate dispatcher.
of
(Class<T>
The type for which a dispatcher should be resolved.
type
,
ClassLoader
The class loader to resolve the proxied type from.
classLoader
)

Resolves an action for creating a dispatcher for the provided type.

protected static <
The resolved type.
T
>
PrivilegedAction<T>

Returns:

An action for creating an appropriate dispatcher.
of
(Class<T>
The type for which a dispatcher should be resolved.
type
,
ClassLoader
The class loader to resolve the proxied type from.
classLoader
,
boolean
true if a proxy class should be manually generated.
generate
)

Resolves an action for creating a dispatcher for the provided type.

public T
run()

Implements java.security.PrivilegedAction.run.

Performs the computation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait