{"record":{"id":"8cc7143645bba997","repo":"apache/pulsar","slug":"s-does-not-implement-s","errorCode":null,"errorMessage":"%s does not implement %s","messagePattern":"(.+?) does not implement (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/util/ClassLoaderUtils.java","lineNumber":76,"sourceCode":"            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}\n","sourceCodeStart":58,"sourceCodeEnd":91,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/util/ClassLoaderUtils.java#L58-L91","documentation":"Thrown by ClassLoaderUtils.implementsClass when the class loads successfully but is not assignable to the required klass parameter — i.e. it does not implement/extend the expected interface or superclass. This guards plugin and strategy loading so only type-correct implementations are accepted.","triggerScenarios":"Calling implementsClass(className, expectedType, classLoader) where the loaded class compiles and loads but does not extend/implement expectedType — e.g. registering a class as a PulsarFunction when it doesn't implement the Function interface.","commonSituations":"Pointing configuration at the wrong class inside a jar (the impl class vs a helper class); loading a plugin built against a different Pulsar interface version; refactoring that moved an interface so the class silently stops implementing it; confusing similar interfaces with the same simple name.","solutions":["Confirm the configured class actually implements/extends the expected interface (check its class hierarchy)","Point the configuration at the correct implementation class, not a helper or wrapper","Rebuild the plugin against the same Pulsar API version as the broker so interface signatures match","Use the full cause chain: load the class yourself and print it, checking klass.isAssignableFrom beforehand"],"exampleFix":"// before\nClassLoaderUtils.implementsClass(\"com.acme.MyHandler\", Function.class, cl); // MyHandler implements Runnable\n// after\npublic class MyHandler implements Function<byte[], byte[]> { ... }\nClassLoaderUtils.implementsClass(\"com.acme.MyHandler\", Function.class, cl);","handlingStrategy":"type-guard","validationCode":"Class<?> c = Class.forName(className, false, classLoader);\nif (!klass.isAssignableFrom(c)) {\n    throw new IllegalArgumentException(className + \" does not implement \" + klass.getName());\n}","typeGuard":"static <T> Class<? extends T> asImplementing(String className, Class<T> klass, ClassLoader cl) throws ClassNotFoundException {\n    Class<?> c = Class.forName(className, false, cl);\n    if (!klass.isAssignableFrom(c)) return null;\n    return c.asSubclass(klass);\n}","tryCatchPattern":"try {\n    ClassLoaderUtils.implementsClass(className, klass, cl);\n} catch (IllegalArgumentException e) {\n    log.error(\"Class {} exists but does not implement {}\", className, klass.getName());\n}","preventionTips":["Check the class hierarchy of plugin classes before registering them","Point config at the concrete implementation, not helper classes","Rebuild plugins against the broker's API version","Keep interfaces stable; bump plugin versions when interfaces change"],"tags":["classloading","type-safety","plugins","reflection"],"backgroundTag":"class-cast-type-mismatch","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"}