Class UberModuleClassLoader

java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
org.elasticsearch.plugins.UberModuleClassLoader
All Implemented Interfaces:
AutoCloseable

public class UberModuleClassLoader extends SecureClassLoader implements AutoCloseable
This classloader will load classes from non-modularized sets of jars. A synthetic module will be created for all jars in the bundle. We want to be able to construct the read relationships in the module graph for this synthetic module, which will make it different from the unnamed (classpath) module.

Internally, we can delegate to a URLClassLoader, which is battle-tested when it comes to reading classes out of jars.

This classloader needs to avoid parent-first search: we'll check classes against a list of packages in this synthetic module, and load a class directly if it's part of this synthetic module. This will keep libraries from clashing.

  • Method Details

    • findClass

      protected Class<?> findClass(String moduleName, String name)
      Overrides:
      findClass in class ClassLoader
      Parameters:
      moduleName - The module name; or null to find the class in the unnamed module for this class loader
      name - The binary name of the class
      Returns:
    • findClass

      protected Class<?> findClass(String name)
      Overrides:
      findClass in class ClassLoader
      Parameters:
      name - The binary name of the class
      Returns:
    • findResource

      protected URL findResource(String moduleName, String name)
      This classloader does not restrict access to resources in its jars. Users should expect the same behavior as that provided by URLClassLoader.
      Overrides:
      findResource in class ClassLoader
      Parameters:
      moduleName - Name of this classloader's synthetic module
      name - The resource name
      Returns:
      a URL for the resource, or null if the resource could not be found, if the module name does not match, or if the loader is closed.
    • findResource

      protected URL findResource(String name)
      This classloader does not restrict access to resources in its jars. Users should expect the same behavior as that provided by URLClassLoader.
      Overrides:
      findResource in class ClassLoader
      Parameters:
      name - The resource name
      Returns:
      a URL for the resource, or null if the resource could not be found, or if the loader is closed.
    • findResources

      protected Enumeration<URL> findResources(String name) throws IOException
      This classloader does not restrict access to resources in its jars. Users should expect the same behavior as that provided by URLClassLoader.
      Overrides:
      findResources in class ClassLoader
      Parameters:
      name - The resource name
      Returns:
      an Enumeration of URLs. If the loader is closed, the Enumeration contains no elements.
      Throws:
      IOException
    • loadClass

      protected Class<?> loadClass(String cn, boolean resolve) throws ClassNotFoundException
      Overrides:
      loadClass in class ClassLoader
      Throws:
      ClassNotFoundException
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception