Class JavaDispatcher<T>

java.lang.Object
net.bytebuddy.utility.dispatcher.JavaDispatcher<T>
Type Parameters:
T - The resolved type.
All Implemented Interfaces:
PrivilegedAction<T>

@Enhance public class JavaDispatcher<T> extends Object implements PrivilegedAction<T>

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 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.

  • Field Details

    • GENERATE_PROPERTY

      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.
      See Also:
  • Constructor Details

    • JavaDispatcher

      protected JavaDispatcher(Class<T> proxy, @MaybeNull ClassLoader classLoader, boolean generate)
      Creates a new dispatcher.
      Parameters:
      proxy - The proxy type.
      classLoader - The class loader to resolve the proxied type from or null if the bootstrap loader should be used.
      generate - true if a proxy class should be manually generated.
  • Method Details

    • of

      public static <T> PrivilegedAction<T> of(Class<T> type)
      Resolves an action for creating a dispatcher for the provided type where the proxied type is resolved from the bootstrap loader.
      Type Parameters:
      T - The resolved type.
      Parameters:
      type - The type for which a dispatcher should be resolved.
      Returns:
      An action for creating an appropriate dispatcher.
    • of

      public static <T> PrivilegedAction<T> of(Class<T> type, @MaybeNull ClassLoader classLoader)
      Resolves an action for creating a dispatcher for the provided type.
      Type Parameters:
      T - The resolved type.
      Parameters:
      type - The type for which a dispatcher should be resolved.
      classLoader - The class loader to resolve the proxied type from.
      Returns:
      An action for creating an appropriate dispatcher.
    • of

      protected static <T> PrivilegedAction<T> of(Class<T> type, @MaybeNull ClassLoader classLoader, boolean generate)
      Resolves an action for creating a dispatcher for the provided type.
      Type Parameters:
      T - The resolved type.
      Parameters:
      type - The type for which a dispatcher should be resolved.
      classLoader - The class loader to resolve the proxied type from.
      generate - true if a proxy class should be manually generated.
      Returns:
      An action for creating an appropriate dispatcher.
    • run

      public T run()
      Specified by:
      run in interface PrivilegedAction<T>