{"record":{"id":"824a105a53cb5714","repo":"apache/pulsar","slug":"class-must-be-in-class-path","errorCode":null,"errorMessage":"Class  must be in class path","messagePattern":"Class  must be in class path","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pulsar-functions/runtime-all/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceMain.java","lineNumber":137,"sourceCode":"            method.invoke(main, args, functionInstanceClsLoader, root);\n        } catch (Throwable e) {\n            try {\n                shutdownLogging();\n            } finally {\n                System.out.println(\"Failed to start function instance.\");\n                e.printStackTrace();\n                Runtime.getRuntime().halt(1);\n            }\n        }\n    }\n\n    public static Object createInstance(String userClassName,\n                                        ClassLoader classLoader) {\n        Class<?> theCls;\n        try {\n            theCls = Class.forName(userClassName, true, classLoader);\n        } catch (ClassNotFoundException | NoClassDefFoundError cnfe) {\n            throw new RuntimeException(\"Class \" + userClassName + \" must be in class path\", cnfe);\n        }\n        Object result;\n        try {\n            Constructor<?> meth = theCls.getDeclaredConstructor();\n            meth.setAccessible(true);\n\n            result = meth.newInstance();\n        } catch (InstantiationException ie) {\n            throw new RuntimeException(\"User class must be concrete\", ie);\n        } catch (NoSuchMethodException e) {\n            throw new RuntimeException(\"Class \" + userClassName + \" doesn't have such method\", e);\n        } catch (IllegalAccessException e) {\n            throw new RuntimeException(\"Class \" + userClassName + \" must have a no-arg constructor\", e);\n        } catch (InvocationTargetException e) {\n            throw new RuntimeException(\"Class \" + userClassName + \" constructor throws exception\", e);\n        }\n        return result;\n    }","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/runtime-all/src/main/java/org/apache/pulsar/functions/instance/JavaInstanceMain.java#L119-L155","documentation":"JavaInstanceMain.createInstance() loads the user function class with Class.forName(userClassName, true, classLoader) on the function instance classloader. If the class (or a type it references during linking) cannot be found, ClassNotFoundException/NoClassDefFoundError is wrapped into RuntimeException(\"Class X must be in class path\").","triggerScenarios":"The function's user jar was not added to the classloader passed to createInstance (jars from loadJar missing), or the configured className is wrong/renamed, or the class references a dependency that is not on the provided classpath.","commonSituations":"Typos or stale FQCN in the function config after refactoring; submitting a function whose jar doesn't contain the class; shaded jar that excluded a needed dependency; package rename between versions.","solutions":["Verify the fully qualified class name in the function config matches an actual class in the submitted jar (check with `jar tf app.jar | grep MyFunction`).","Rebuild/re-submit the function jar ensuring the class and its dependencies are packaged (shade or bundle deps).","Confirm the jar URL(s) passed to loadJar include the user jar file.","Check for NoClassDefFoundError cause — a missing dependency class, not just the function class itself."],"exampleFix":"// before (stale name after refactor)\n--className com.example.OldFunctionName\n// after\n--className com.example.MyFunction","handlingStrategy":"validation","validationCode":"// verify before submitting the function\nProcess p = new ProcessBuilder(\"jar\", \"tf\", \"app.jar\").start();\n// or in-process:\nboolean found = java.util.Collections.list(loader.getResources(\"com/example/MyFunction.class\")).size() > 0;","typeGuard":"boolean classLoadable(ClassLoader cl, String fcn) { try { Class.forName(fcn, false, cl); return true; } catch (Throwable t) { return false; } }","tryCatchPattern":"try { Object f = JavaInstanceMain.createInstance(className, cl); } catch (RuntimeException e) { if (e.getCause() instanceof NoClassDefFoundError) { /* missing dependency, not just the class */ } throw e; }","preventionTips":["Validate the className exists in the jar at submission time (broker-side validation or CI check).","Shade/bundle all dependencies into the function jar.","Grep the jar (`jar tf`) for the exact FQCN before deploying.","Avoid renaming packages without re-submitting updated function configs."],"tags":["classpath","reflection","classnotfound","configuration"],"backgroundTag":"classnotfound","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"}