Class SimpleInstrumentableClassLoader


public class SimpleInstrumentableClassLoader extends OverridingClassLoader
Simplistic implementation of an instrumentable ClassLoader.

Usable in tests and standalone environments.

Since:
2.0
Author:
Rod Johnson, Costin Leau
  • Constructor Details

    • SimpleInstrumentableClassLoader

      public SimpleInstrumentableClassLoader(@Nullable ClassLoader parent)
      Create a new SimpleInstrumentableClassLoader for the given ClassLoader.
      Parameters:
      parent - the ClassLoader to build an instrumentable ClassLoader for
  • Method Details

    • addTransformer

      public void addTransformer(ClassFileTransformer transformer)
      Add a ClassFileTransformer to be applied by this ClassLoader.
      Parameters:
      transformer - the ClassFileTransformer to register
    • transformIfNecessary

      protected byte[] transformIfNecessary(String name, byte[] bytes)
      Description copied from class: OverridingClassLoader
      Transformation hook to be implemented by subclasses.

      The default implementation simply returns the given bytes as-is.

      Overrides:
      transformIfNecessary in class OverridingClassLoader
      Parameters:
      name - the fully-qualified name of the class being transformed
      bytes - the raw bytes of the class
      Returns:
      the transformed bytes (never null; same as the input bytes if the transformation produced no changes)