{"record":{"id":"f5cc0c5ec4f794ce","repo":"apache/pulsar","slug":"cannot-find-load-class","errorCode":null,"errorMessage":"Cannot find/load class ","messagePattern":"Cannot find/load class ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/util/ClassLoaderUtils.java","lineNumber":72,"sourceCode":"        Class<?> objectClass;\n        try {\n            objectClass = Class.forName(className);\n        } catch (ClassNotFoundException | NoClassDefFoundError e) {\n            if (classLoader != null) {\n                objectClass = classLoader.loadClass(className);\n            } else {\n                throw e;\n            }\n        }\n        return objectClass;\n    }\n\n    public static void implementsClass(String className, Class<?> klass, ClassLoader classLoader) {\n        Class<?> objectClass;\n        try {\n            objectClass = loadClass(className, classLoader);\n        } catch (ClassNotFoundException | NoClassDefFoundError e) {\n            throw new IllegalArgumentException(\"Cannot find/load class \" + className);\n        }\n\n        if (!klass.isAssignableFrom(objectClass)) {\n            throw new IllegalArgumentException(\n                    String.format(\"%s does not implement %s\", className, klass.getName()));\n        }\n    }\n\n    public static void closeClassLoader(ClassLoader classLoader) {\n        if (classLoader instanceof Closeable) {\n            try {\n                ((Closeable) classLoader).close();\n            } catch (IOException e) {\n                log.error().attr(\"classLoader\", classLoader).exception(e).log(\"Error closing classloader\");\n            }\n        }\n    }\n}","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/util/ClassLoaderUtils.java#L54-L90","documentation":"Thrown by ClassLoaderUtils.implementsClass when loadClass cannot find or link the named class — a ClassNotFoundException or NoClassDefFoundError is caught and rethrown as an IllegalArgumentException with 'Cannot find/load class '. Note the cause is dropped, so the underlying linking error is not visible in the new exception.","triggerScenarios":"Calling implementsClass(className, klass, classLoader) where the className is misspelled, the class is missing from the given ClassLoader, the class fails static initialization (NoClassDefFoundError), or a dependency class is missing at link time.","commonSituations":"Plugin/nar jar not on the broker classpath; function/searchplug-in configuration pointing at a class that was renamed between versions; wrong ClassLoader passed (e.g. system loader instead of the nar loader); missing transitive dependencies causing NoClassDefFoundError at first use.","solutions":["Verify the fully-qualified class name in configuration is spelled correctly and matches the deployed jar","Ensure the jar containing the class (and its dependencies) is deployed to the location the classLoader reads","Check logs for the original ClassNotFoundException/NoClassDefFoundError cause, since this exception drops it","Pass the correct ClassLoader (e.g. the plugin/nar class loader) rather than the default one"],"exampleFix":"// before\nClassLoaderUtils.implementsClass(\"com.acme.MyFunction\", Function.class, classLoader); // jar not deployed\n// after\n// deploy my-function.jar to the functions directory first, then:\nClassLoader cl = new URLClassLoader(new File(\"functions/my-function.jar\").toURI().toURL(), parentCl);\nClassLoaderUtils.implementsClass(\"com.acme.MyFunction\", Function.class, cl);","handlingStrategy":"validation","validationCode":"try {\n    Class.forName(className, false, classLoader);\n} catch (ClassNotFoundException | NoClassDefFoundError e) {\n    throw new IllegalStateException(\"class not loadable from given classloader: \" + className, e);\n}","typeGuard":"static boolean isClassLoadable(String className, ClassLoader cl) {\n    try { Class.forName(className, false, cl); return true; }\n    catch (ClassNotFoundException | NoClassDefFoundError e) { return false; }\n}","tryCatchPattern":"try {\n    ClassLoaderUtils.implementsClass(className, Function.class, cl);\n} catch (IllegalArgumentException e) {\n    log.error(\"Cannot load plugin class {} (check jar deployment/classpath)\", className);\n    throw e;\n}","preventionTips":["Verify the jar is deployed where the classLoader resolves it","Log the original cause — this error message drops ClassNotFoundException/NoClassDefFoundError details","Use the correct (plugin/nar) class loader, not the system one","Validate plugin config class names at startup, not lazily at runtime"],"tags":["classloading","reflection","plugins","configuration"],"backgroundTag":"class-not-found","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}