apache/pulsar · error · IllegalStateException

Classloading is not enabled

Error message

Classloading is not enabled

What it means

FunctionFilePackage can be constructed without classloading support enabled. createClassLoader (called from getClassLoader) throws IllegalStateException when classloading was not enabled at construction, because no NAR/URL class loader can be built.

Source

Thrown at pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionFilePackage.java:169

            if (isNar) {
                try {
                    return NarClassLoaderBuilder.builder()
                            .narFile(file)
                            .extractionDirectory(narExtractionDirectory)
                            .build();
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            } else {
                try {
                    return new URLClassLoader(new java.net.URL[] {file.toURI().toURL()},
                            NarClassLoader.class.getClassLoader());
                } catch (MalformedURLException e) {
                    throw new UncheckedIOException(e);
                }
            }
        } else {
            throw new IllegalStateException("Classloading is not enabled");
        }
    }

    @Override
    public String toString() {
        return "FunctionFilePackage{"
                + "file=" + file
                + ", isNar=" + isNar
                + '}';
    }
}

View on GitHub (pinned to 820761864e)

Solutions

  1. Create the FunctionFilePackage with classloading enabled before requesting a class loader.
  2. Use the appropriate accessor for metadata-only use cases instead of getClassLoader().
  3. Check the constructor/flag that controls classloading in your call path.

Example fix

// before
FunctionFilePackage pkg = new FunctionFilePackage(path, /* enableClassloading */ false);
ClassLoader cl = pkg.getClassLoader(); // IllegalStateException
// after
FunctionFilePackage pkg = new FunctionFilePackage(path, /* enableClassloading */ true);
ClassLoader cl = pkg.getClassLoader();
Defensive patterns

Strategy: type-guard

Validate before calling

// enable classloading at construction when you will need a ClassLoader
FunctionFilePackage pkg = new FunctionFilePackage(path, /* enableClassloading */ true);

Type guard

static boolean canGetClassLoader(FunctionFilePackage pkg) {
    try { pkg.getClassLoader(); return true; }
    catch (IllegalStateException e) { return false; }
}

Try / catch

try {
    ClassLoader cl = pkg.getClassLoader();
    // use cl
} catch (IllegalStateException e) {
    // classloading disabled: recreate the package with classloading enabled
}

Prevention

When it happens

Trigger: Calling getClassLoader() on a FunctionFilePackage instance that was created with classloading disabled.

Common situations: Using the package object only for metadata extraction but then accidentally invoking getClassLoader(); API misuse after a refactor changed constructor flags.

Related errors


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/1f5668608fc8ac12. Report an issue: GitHub.