{"record":{"id":"1f5668608fc8ac12","repo":"apache/pulsar","slug":"classloading-is-not-enabled","errorCode":null,"errorMessage":"Classloading is not enabled","messagePattern":"Classloading is not enabled","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionFilePackage.java","lineNumber":169,"sourceCode":"            if (isNar) {\n                try {\n                    return NarClassLoaderBuilder.builder()\n                            .narFile(file)\n                            .extractionDirectory(narExtractionDirectory)\n                            .build();\n                } catch (IOException e) {\n                    throw new UncheckedIOException(e);\n                }\n            } else {\n                try {\n                    return new URLClassLoader(new java.net.URL[] {file.toURI().toURL()},\n                            NarClassLoader.class.getClassLoader());\n                } catch (MalformedURLException e) {\n                    throw new UncheckedIOException(e);\n                }\n            }\n        } else {\n            throw new IllegalStateException(\"Classloading is not enabled\");\n        }\n    }\n\n    @Override\n    public String toString() {\n        return \"FunctionFilePackage{\"\n                + \"file=\" + file\n                + \", isNar=\" + isNar\n                + '}';\n    }\n}\n","sourceCodeStart":151,"sourceCodeEnd":181,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionFilePackage.java#L151-L181","documentation":"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.","triggerScenarios":"Calling getClassLoader() on a FunctionFilePackage instance that was created with classloading disabled.","commonSituations":"Using the package object only for metadata extraction but then accidentally invoking getClassLoader(); API misuse after a refactor changed constructor flags.","solutions":["Create the FunctionFilePackage with classloading enabled before requesting a class loader.","Use the appropriate accessor for metadata-only use cases instead of getClassLoader().","Check the constructor/flag that controls classloading in your call path."],"exampleFix":"// before\nFunctionFilePackage pkg = new FunctionFilePackage(path, /* enableClassloading */ false);\nClassLoader cl = pkg.getClassLoader(); // IllegalStateException\n// after\nFunctionFilePackage pkg = new FunctionFilePackage(path, /* enableClassloading */ true);\nClassLoader cl = pkg.getClassLoader();","handlingStrategy":"type-guard","validationCode":"// enable classloading at construction when you will need a ClassLoader\nFunctionFilePackage pkg = new FunctionFilePackage(path, /* enableClassloading */ true);","typeGuard":"static boolean canGetClassLoader(FunctionFilePackage pkg) {\n    try { pkg.getClassLoader(); return true; }\n    catch (IllegalStateException e) { return false; }\n}","tryCatchPattern":"try {\n    ClassLoader cl = pkg.getClassLoader();\n    // use cl\n} catch (IllegalStateException e) {\n    // classloading disabled: recreate the package with classloading enabled\n}","preventionTips":["Enable classloading whenever you plan to call getClassLoader().","Keep construction flags and later usage consistent.","Prefer metadata-only accessors when you don't need classes loaded."],"tags":["pulsar-functions","classpath","illegal-state"],"backgroundTag":"classloading-not-enabled","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}