Class HierarchyClassLoader

java.lang.Object
java.lang.ClassLoader
java.security.SecureClassLoader
java.net.URLClassLoader
net.minestom.server.extras.selfmodification.HierarchyClassLoader
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
MinestomExtensionClassLoader, MinestomRootClassLoader

public abstract class HierarchyClassLoader extends URLClassLoader
Classloader part of a hierarchy of classloader.
  • Field Details

  • Constructor Details

  • Method Details

    • addChild

      public void addChild(@NotNull @NotNull MinestomExtensionClassLoader loader)
    • findLibrary

      public String findLibrary(String libname)
      Overrides:
      findLibrary in class ClassLoader
    • getResourceAsStreamWithChildren

      @Nullable public @Nullable InputStream getResourceAsStreamWithChildren(@NotNull @NotNull String name)
      Finds a resource under the given name within this classloader, or if that fails, in any of its children. If the resource is found, the resource is opened as an InputStream, otherwise null is returned.

      This method distinguishes itself from URLClassLoader.getResourceAsStream(String), which will first query the parent classloader and only then this classloader. Further, URLClassLoader.getResourceAsStream(String) does not query children classloaders.

      When failing to open a resource using URL.openStream(), the resource is deemed to no exist in this classloader and will search in children classloaders.

      The InputStream returned by this method must be closed manually, it is unspecified whether the returned object will be closed whenever this classloader is closed. A warning will be logged in that circumstance.

      Parameters:
      name - The pathname of the resource. See URLClassLoader.findResource(String).
      Returns:
      The InputStream of the corresponding found resource, or null if such a resource does not exist.
      Since:
      0.0.1
      Implementation Note:
      Search occurs depth-first, which means that registration order can matter quite a lot.
    • getResourceAsURLWithChildren

      @Nullable @AvailableSince("4.0.0-a20241006") public @Nullable URL getResourceAsURLWithChildren(@NotNull @NotNull String name)
      Finds a resource under the given name within this classloader, or if that fails, in any of its children. If the resource is found, the resource is returned as an URL, otherwise null is returned.

      This method distinguishes itself from ClassLoader.getResource(String), which will first query the parent classloader and only then this classloader. Further, ClassLoader.getResource(String) does not query children classloaders.

      Parameters:
      name - The pathname of the resource.
      Returns:
      The URL of the corresponding found resource, or null if such a resource does not exist.
      Since:
      4.0.0-a20241006
      Implementation Note:
      Search occurs depth-first, which means that registration order can matter quite a lot.
    • removeChildInHierarchy

      public void removeChildInHierarchy(MinestomExtensionClassLoader child)
    • getName

      public String getName()
      Overrides:
      getName in class ClassLoader