{"record":{"id":"a91770a0764a4197","repo":"apache/pulsar","slug":"does-not-implement","errorCode":null,"errorMessage":" does not implement ","messagePattern":" does not implement ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/util/Reflections.java","lineNumber":75,"sourceCode":"     * Create an instance of <code>userClassName</code> using provided <code>classLoader</code>.\n     * This instance should implement the provided interface <code>xface</code>.\n     *\n     * @param userClassName user class name\n     * @param xface the interface that the reflected instance should implement\n     * @param classLoader class loader to load the class.\n     * @return the instance\n     */\n    public static <T> T createInstance(String userClassName,\n                                       Class<T> xface,\n                                       ClassLoader classLoader) {\n        Class<?> theCls;\n        try {\n            theCls = Class.forName(userClassName, true, classLoader);\n        } catch (ClassNotFoundException | NoClassDefFoundError cnfe) {\n            throw new RuntimeException(\"User class must be in class path\", cnfe);\n        }\n        if (!xface.isAssignableFrom(theCls)) {\n            throw new RuntimeException(userClassName + \" does not implement \" + xface.getName());\n        }\n        @SuppressWarnings(\"unchecked\") // safe: theCls is verified to be assignable to xface\n        Class<T> tCls = (Class<T>) theCls.asSubclass(xface);\n        T result;\n        try {\n            @SuppressWarnings(\"unchecked\") // safe: constructor cache is keyed by theCls which extends T\n            Constructor<T> meth = (Constructor<T>) constructorCache.get(theCls);\n            if (null == meth) {\n                meth = tCls.getDeclaredConstructor();\n                meth.setAccessible(true);\n                constructorCache.put(theCls, meth);\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(\"User class must have a no-arg constructor\", e);\n        } catch (IllegalAccessException e) {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/util/Reflections.java#L57-L93","documentation":"After loading the class, createInstance checks `xface.isAssignableFrom(theCls)`. If the loaded class does not implement/extend the requested interface, this RuntimeException is thrown with a message of the form `<className> does not implement <interfaceName>`. It guards against misconfigured class names pointing at unrelated classes.","triggerScenarios":"Configuring a class name that exists on the classpath but does not implement the expected interface `xface`, e.g. pointing an interceptor setting at a random class.","commonSituations":"Copy-pasting a class name from another config key; upgrading Pulsar where the interface moved packages so the old class no longer matches; implementing the wrong interface version.","solutions":["Make the class implement/extend the interface named in the message","Fix the configured class name to one that implements the expected interface","After upgrades, recompile the plugin against the new interface package/signature"],"exampleFix":"// before\nclass MyFilter { } // does not implement Filter\n// after\nclass MyFilter implements Filter { }","handlingStrategy":"validation","validationCode":"// verify the interface relationship before instantiating\nClass<?> cls = Class.forName(className, true, classLoader);\nif (!XFace.class.isAssignableFrom(cls)) {\n    throw new IllegalArgumentException(className + \" does not implement \" + XFace.getName());\n}","typeGuard":"boolean implementsX(Class<?> cls) { return XFace.class.isAssignableFrom(cls); }","tryCatchPattern":"try {\n    T obj = Reflections.createInstance(className, XFace.class, classLoader);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\" does not implement \")) {\n        throw new IllegalArgumentException(\"Wrong class configured: \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["Copy fully qualified class names from the plugin's own documentation/source, not from memory","After upgrades, recompile plugins against the current interface packages","Add a config-validation step at startup that checks isAssignableFrom before use"],"tags":["reflection","type-mismatch","configuration"],"backgroundTag":"class-does-not-implement-interface","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"}