Package com.ultikits.ultitools.utils
Class ClassLoaderUtils
java.lang.Object
com.ultikits.ultitools.utils.ClassLoaderUtils
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidemitClassloadFilterAuditSummary(String moduleName) GEN-07 (D-14) package-boundary bridge: emits the package-privateClassloadFilterAudit's one-INFO-per-module summary formoduleName, always -- even when nothing was recorded (a module the removed layers would have refused nothing from is itself the measurement, not silence).static ClassLoaderGet the JavaPlugin class loader.static Class<?> Load a class using the plugin class loader with security validation.static Class<?> Load a class using the plugin class loader with initialization control and security validation.static Class<?> loadPluginClass(String className) Safely load a class that extends UltiToolsPlugin.static voidrecordClassloadFilterAudit(String moduleName, String className) GEN-07 (D-14) package-boundary bridge into the package-privateClassloadFilterAuditevaluator, forPluginManager(a different package,manager) to record what the removed classload filter layers would have refused forclassNameduringmoduleName's scan.static booleanvalidateClassLoaderHierarchy(ClassLoader classLoader) Validate that a class loader has the correct parent hierarchy.private static voidvalidateClassName(String className) Validate class name format.
-
Field Details
-
VALID_CLASS_NAME_PATTERN
-
-
Constructor Details
-
ClassLoaderUtils
public ClassLoaderUtils()
-
-
Method Details
-
validateClassName
Validate class name format.GEN-07 (D-13, since 6.3.0): this method no longer calls into
SecurityPolicyat 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_PATTERNis the only check left here, and it is input validation, not security: anullis guarded explicitly before the regex runs (a barePattern.matcher(null)throwsNullPointerExceptionrather than failing to match), so anull/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
Get the JavaPlugin class loader. This should be used as the parent class loader for any custom class loaders.- Returns:
- JavaPlugin class loader
-
loadClass
Load a class using the plugin class loader with security validation.- Parameters:
className- class name- Returns:
- loaded class
- Throws:
ClassNotFoundException- if class not foundSecurityException- 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 nameinitialize- whether to initialize the class- Returns:
- loaded class
- Throws:
ClassNotFoundException- if class not foundSecurityException- 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 foundSecurityException- if class is dangerous or invalid
-
recordClassloadFilterAudit
GEN-07 (D-14) package-boundary bridge into the package-privateClassloadFilterAuditevaluator, forPluginManager(a different package,manager) to record what the removed classload filter layers would have refused forclassNameduringmoduleName's scan.ClassloadFilterAuditstays 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 outsideutilsneeds, mirroring the position of theloadClass(String)call site it is always paired with. Purely observational: never throws, never refuses, and does not affect whetherclassNameloads.- Parameters:
moduleName- the module (or scan unit) currently being evaluatedclassName- the class name being evaluated- Since:
- 6.3.0
-
emitClassloadFilterAuditSummary
GEN-07 (D-14) package-boundary bridge: emits the package-privateClassloadFilterAudit's one-INFO-per-module summary formoduleName, 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 pointModuleScanDiagnostics.emitSummaryis called for the same module, so the two diagnostics land together.- Parameters:
moduleName- the module whose scan just finished- Since:
- 6.3.0
-
validateClassLoaderHierarchy
Validate that a class loader has the correct parent hierarchy.- Parameters:
classLoader- class loader to validate- Returns:
- true if valid, false otherwise
-