Class ClassLoaderUtils

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

public class ClassLoaderUtils extends Object
Utility class for ensuring proper class loader usage throughout the plugin. All class loaders created in this plugin should use the JavaPlugin class loader as parent.
  • 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.

      GEN-07 (D-13, since 6.3.0): this method no longer calls into SecurityPolicy at all -- that class's four name-based checks are now unconditional no-ops (D-12), and the framework must not call a method it has just declared to do nothing. VALID_CLASS_NAME_PATTERN is the only check left here, and it is input validation, not security: a null is guarded explicitly before the regex runs (a bare Pattern.matcher(null) throws NullPointerException rather than failing to match), so a null/blank/malformed class name is still rejected, just for a different reason than before.

      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 JavaPlugin class loader. This should be used as the parent class loader for any custom class loaders.
      Returns:
      JavaPlugin class loader
    • loadClass

      public static Class<?> loadClass(String className) throws ClassNotFoundException, SecurityException
      Load a class using the plugin class loader with security validation.
      Parameters:
      className - class name
      Returns:
      loaded class
      Throws:
      ClassNotFoundException - if class not found
      SecurityException - if class is dangerous
    • loadClass

      public static Class<?> loadClass(String className, boolean initialize) throws ClassNotFoundException, SecurityException
      Load a class using the plugin class loader with initialization control and security validation.
      Parameters:
      className - class name
      initialize - whether to initialize the class
      Returns:
      loaded class
      Throws:
      ClassNotFoundException - if class not found
      SecurityException - if class is dangerous
    • loadPluginClass

      public static Class<?> loadPluginClass(String className) throws ClassNotFoundException, SecurityException
      Safely load a class that extends UltiToolsPlugin. This method provides additional validation for plugin classes.
      Parameters:
      className - class name
      Returns:
      loaded plugin class
      Throws:
      ClassNotFoundException - if class not found
      SecurityException - if class is dangerous or invalid
    • recordClassloadFilterAudit

      public static void recordClassloadFilterAudit(String moduleName, String className)
      GEN-07 (D-14) package-boundary bridge into the package-private ClassloadFilterAudit evaluator, for PluginManager (a different package, manager) to record what the removed classload filter layers would have refused for className during moduleName's scan. ClassloadFilterAudit stays package-private per D-14 (its four relocated lists must not become part of the public surface); this method is the one public seam a caller outside utils needs, mirroring the position of the loadClass(String) call site it is always paired with. Purely observational: never throws, never refuses, and does not affect whether className loads.
      Parameters:
      moduleName - the module (or scan unit) currently being evaluated
      className - the class name being evaluated
      Since:
      6.3.0
    • emitClassloadFilterAuditSummary

      public static void emitClassloadFilterAuditSummary(String moduleName)
      GEN-07 (D-14) package-boundary bridge: emits the package-private ClassloadFilterAudit's one-INFO-per-module summary for moduleName, always -- even when nothing was recorded (a module the removed layers would have refused nothing from is itself the measurement, not silence). Call once, at the same point ModuleScanDiagnostics.emitSummary is called for the same module, so the two diagnostics land together.
      Parameters:
      moduleName - the module whose scan just finished
      Since:
      6.3.0
    • validateClassLoaderHierarchy

      public static boolean validateClassLoaderHierarchy(ClassLoader classLoader)
      Validate that a class loader has the correct parent hierarchy.
      Parameters:
      classLoader - class loader to validate
      Returns:
      true if valid, false otherwise