Class ClassLoaderUtils

java.lang.Object
com.ultikits.ultitools.utils.ClassLoaderUtils

public class ClassLoaderUtils extends Object
Helpers for framework and module class loading and for loading with an explicit owner loader.
  • Field Details

    • VALID_CLASS_NAME_PATTERN

      private static final Pattern VALID_CLASS_NAME_PATTERN
  • Constructor Details

    • ClassLoaderUtils

      public ClassLoaderUtils()
  • Method Details

    • validateClassName

      private static void validateClassName(String className) throws SecurityException
      Validate class name format.

      This is input validation, not a security boundary. Null, blank and malformed names are rejected before the classloader is called.

      Parameters:
      className - class name to validate
      Throws:
      SecurityException - if the class name is null or does not match the expected format
    • getPluginClassLoader

      public static ClassLoader getPluginClassLoader()
      Get the shared loader for framework and module classes, not for external plugin classes.
      Returns:
      framework and module class loader
    • loadClass

      public static Class<?> loadClass(String className) throws ClassNotFoundException, SecurityException
      Load a framework or module class with name-format validation. This method does not use an external plugin's own loader: for an external plugin class, call loadClass on that plugin's class loader directly.
      Parameters:
      className - class name
      Returns:
      loaded class
      Throws:
      ClassNotFoundException - if class not found
      SecurityException - if the class name format is invalid
    • loadClass

      @Internal public static Class<?> loadClass(String className, ClassLoader owner) throws ClassNotFoundException, SecurityException
      Load a class by validating its name and delegating to the supplied owner loader. This method does not request class initialization.

      For framework use only. Modules should not call this method. It is not covered by the public API compatibility policy and may change or be removed in any release.

      Parameters:
      className - class name
      owner - non-null class loader to use for lookup; there is no fallback loader
      Returns:
      loaded class
      Throws:
      ClassNotFoundException - if the owner loader cannot find the class; the loader's exception is the cause
      NullPointerException - if the name is valid and the owner loader is null
      SecurityException - if the class name is null or malformed, even if the owner loader is null
    • loadClass

      public static Class<?> loadClass(String className, boolean initialize) throws ClassNotFoundException, SecurityException
      Load a framework or module class with initialization control and name-format validation. This does not use an external plugin's own loader.
      Parameters:
      className - class name
      initialize - whether to initialize the class
      Returns:
      loaded class
      Throws:
      ClassNotFoundException - if class not found
      SecurityException - if the class name format is invalid
    • loadPluginClass

      public static Class<?> loadPluginClass(String className) throws ClassNotFoundException, SecurityException
      Load and validate an UltiToolsPlugin subclass using the shared module loader. This method is not for external Bukkit plugin classes.
      Parameters:
      className - class name
      Returns:
      loaded plugin class
      Throws:
      ClassNotFoundException - if class not found
      SecurityException - if the class name or plugin hierarchy is invalid
    • validateClassLoaderHierarchy

      public static boolean validateClassLoaderHierarchy(ClassLoader classLoader)
      Validate a class loader's parent hierarchy against the shared framework and module loader. External Bukkit plugin loaders are not required to use this hierarchy.
      Parameters:
      classLoader - class loader to validate
      Returns:
      true if valid, false otherwise