Class ClassInjector.UsingReflection

java.lang.Object
net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
net.bytebuddy.dynamic.loading.ClassInjector.UsingReflection
All Implemented Interfaces:
ClassInjector
Enclosing interface:
ClassInjector

@Enhance public static class ClassInjector.UsingReflection extends ClassInjector.AbstractBase
A class injector that uses reflective method calls.
  • Field Details

    • DISPATCHER

      The dispatcher to use for accessing a class loader via reflection.
    • SYSTEM

      private static final ClassInjector.UsingReflection.System SYSTEM
      A proxy for java.lang.System to access the security manager if available.
    • CHECK_PERMISSION

      private static final Method CHECK_PERMISSION
      The java.lang.SecurityManager#checkPermission method or null if not available.
    • classLoader

      private final ClassLoader classLoader
      The class loader into which the classes are to be injected.
    • protectionDomain

      The protection domain that is used when loading classes.
    • packageDefinitionStrategy

      private final PackageDefinitionStrategy packageDefinitionStrategy
      The package definer to be queried for package definitions.
    • forbidExisting

      private final boolean forbidExisting
      Determines if an exception should be thrown when attempting to load a type that already exists.
  • Constructor Details

    • UsingReflection

      public UsingReflection(ClassLoader classLoader)
      Creates a new injector for the given ClassLoader and a default ProtectionDomain and a trivial PackageDefinitionStrategy which does not trigger an error when discovering existent classes.
      Parameters:
      classLoader - The ClassLoader into which new class definitions are to be injected. Must not be the bootstrap loader.
    • UsingReflection

      public UsingReflection(ClassLoader classLoader, @MaybeNull ProtectionDomain protectionDomain)
      Creates a new injector for the given ClassLoader and a default PackageDefinitionStrategy where the injection of existent classes does not trigger an error.
      Parameters:
      classLoader - The ClassLoader into which new class definitions are to be injected. Must not be the bootstrap loader.
      protectionDomain - The protection domain to apply during class definition.
    • UsingReflection

      public UsingReflection(ClassLoader classLoader, @MaybeNull ProtectionDomain protectionDomain, PackageDefinitionStrategy packageDefinitionStrategy, boolean forbidExisting)
      Creates a new injector for the given ClassLoader and ProtectionDomain.
      Parameters:
      classLoader - The ClassLoader into which new class definitions are to be injected.Must not be the bootstrap loader.
      protectionDomain - The protection domain to apply during class definition.
      packageDefinitionStrategy - The package definer to be queried for package definitions.
      forbidExisting - Determines if an exception should be thrown when attempting to load a type that already exists.
  • Method Details

    • doPrivileged

      @Enhance private static <T> T doPrivileged(PrivilegedAction<T> action)
      A proxy for java.security.AccessController#doPrivileged that is activated if available.
      Type Parameters:
      T - The type of the action's resolved value.
      Parameters:
      action - The action to execute from a privileged context.
      Returns:
      The action's resolved value.
    • isAlive

      public boolean isAlive()
      Indicates if this class injector is available on the current VM.
      Returns:
      true if this injector is available on the current VM.
    • injectRaw

      public Map<String,Class<?>> injectRaw(Set<String> names, ClassFileLocator classFileLocator)
      Injects the given types into the represented class loader.
      Parameters:
      names - The names of the types to load via injection.
      classFileLocator - The class file locator to use for resolving binary representations.
      Returns:
      The loaded types that were passed as arguments.
    • isAvailable

      public static boolean isAvailable()
      Indicates if this class injection is available on the current VM.
      Returns:
      true if this class injection is available.
    • ofSystemClassLoader

      public static ClassInjector ofSystemClassLoader()
      Creates a class injector for the system class loader.
      Returns:
      A class injector for the system class loader.