Home /Modules/connector/CLASS_LOADER.md

CLASS_LOADER.md

connector/CLASS_LOADER.md · 53 line(s) · markdown

SleelaClassLoader — intelligent loader of raw compiled classes

SleelaClassLoader (connector/java/.../SleelaClassLoader.java) is a Class.forName()-style facility for the SLeeLa → Java bridge — but hardened. It resolves raw compiled classes (from the classpath or from operator-supplied .class directories / .jar files) under an explicit allow-list, with caching and fail-closed behavior.

Why not just Class.forName(userString)?

A bare Class.forName() on a user-supplied name is a real hazard: it can resolve and static-initialize any class on the classpath, which is a code-execution / deserialization risk. SleelaClassLoader keeps the convenience but removes the danger, matching the allow-list posture already used by the java28 memory server.

What "intelligent" means

PropertyBehavior
Allow-listedA class resolves only if its exact FQCN is allowed, or it is under an allowed package prefix.
Explicit rootsaddRoot(dirOrJar) layers raw .class directories and .jar files via a URLClassLoader over the bridge's own loader.
Non-initializing by defaultresolve(name) does not run static initializers; resolve(name, true) opts in.
CachedSuccessful resolutions are memoized (same Class instance returned).
Fail closedA disallowed / missing / unlinkable class throws ClassResolutionException; junk names throw IllegalArgumentException. Never an arbitrary load.

Thread-safe; AutoCloseable (closing releases any URLClassLoader opened for roots).

Usage

try (SleelaClassLoader loader = new SleelaClassLoader()) {
    loader.addRoot(Path.of("build/plugins"));   // dir of raw .class files
    loader.addRoot(Path.of("libs/widgets.jar")); // or a jar
    loader.allowPackage("com.acme");             // or allowClass("com.acme.Widget")

    if (loader.isAllowed("com.acme.Widget")) {
        Class<?> type = loader.resolve("com.acme.Widget");        // no static init
        // ... reflect / instantiate as needed ...
        Class<?> live = loader.resolve("com.acme.Widget", true);  // run static init
    }
}

Errors