Class CachedClassfiles

java.lang.Object
mockit.internal.state.CachedClassfiles
All Implemented Interfaces:
ClassFileTransformer

public final class CachedClassfiles extends Object implements ClassFileTransformer
Holds a map of internal class names to the corresponding class files (bytecode arrays), for the classes that have already been loaded during the test run. These classfiles are not necessarily the same as those stored in the corresponding ".class" files available from the runtime classpath. If any third-party ClassFileTransformers are active, those original classfiles may have been modified before being loaded by the JVM. JMockit installs a ClassFileTransformer of its own which saves all potentially modified classfiles here.

This bytecode cache allows classes to be mocked and un-mocked correctly, even in the presence of other bytecode modification agents such as the AspectJ load-time weaver.

  • Field Details

  • Method Details

    • transform

      @Nullable public byte[] transform(@Nullable ClassLoader loader, String classDesc, @Nullable Class<?> classBeingRedefinedOrRetransformed, @Nullable ProtectionDomain protectionDomain, @NonNull byte[] classfileBuffer)
      Specified by:
      transform in interface ClassFileTransformer
    • getClassfile

      @Nullable public static byte[] getClassfile(@NonNull String classDesc)
    • getClassfile

      @Nullable public static byte[] getClassfile(@NonNull Class<?> aClass)
    • getClassfile

      @Nullable public static byte[] getClassfile(@Nullable ClassLoader loader, @NonNull String internalClassName)
    • addClassfile

      public static void addClassfile(@NonNull Class<?> aClass, @NonNull byte[] classfile)