Class ClassLoaderDefineClassPatcher


  • public class ClassLoaderDefineClassPatcher
    extends Object
    Classloader patch which will redefine each patch via Javassist in the target classloader.

    Note that the class will typically be already accessible by parent classloader, but if it is loaded from parent classloader, it does not have access to other child classloader classes.

    Redefine will work only if the class was not loaded by the child classloader. This may not be used for Plugin class itself, because some target library classes may be enhanced by plugin reference (e.g. to set some initialized property). Although the class resides in parent classloader it cannot be redefined in child classloader with other definition - the classloader already knows about this class. This is the reason, why plugin class cannot be executed in child classloader.

    Author:
    Jiri Bubnik
    • Constructor Detail

      • ClassLoaderDefineClassPatcher

        public ClassLoaderDefineClassPatcher()
    • Method Detail

      • patch

        public void patch​(ClassLoader classLoaderFrom,
                          String pluginPath,
                          ClassLoader classLoaderTo,
                          ProtectionDomain protectionDomain)
        Patch the classloader.
        Parameters:
        classLoaderFrom - classloader to load classes from
        pluginPath - path to copy
        classLoaderTo - classloader to copy classes to
        protectionDomain - required protection in target classloader
      • isPatchAvailable

        public boolean isPatchAvailable​(ClassLoader classLoader)
        Check if the classloader can be patched. Typically skip synthetic classloaders.
        Parameters:
        classLoader - classloader to check
        Returns:
        if true, call patch()