{"record":{"id":"da1d6a44f7af3437","repo":"apache/dubbo","slug":"input-type-clazz-doesn-t-implement-extension","errorCode":null,"errorMessage":"Input type ${clazz} doesn't implement Extension ${type}","messagePattern":"Input type (.+?) doesn't implement Extension (.+?)","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java","lineNumber":693,"sourceCode":"            cachedAdaptiveClass = clazz;\n        }\n    }\n\n    /**\n     * Replace the existing extension via API\n     *\n     * @param name  extension name\n     * @param clazz extension class\n     * @throws IllegalStateException when extension to be placed doesn't exist\n     * @deprecated not recommended any longer, and use only when test\n     */\n    @Deprecated\n    public void replaceExtension(String name, Class<?> clazz) {\n        checkDestroyed();\n        getExtensionClasses(); // load classes\n\n        if (!type.isAssignableFrom(clazz)) {\n            throw new IllegalStateException(\"Input type \" + clazz + \" doesn't implement Extension \" + type);\n        }\n        if (clazz.isInterface()) {\n            throw new IllegalStateException(\"Input type \" + clazz + \" can't be interface!\");\n        }\n\n        if (!clazz.isAnnotationPresent(Adaptive.class)) {\n            if (StringUtils.isBlank(name)) {\n                throw new IllegalStateException(\"Extension name is blank (Extension \" + type + \")!\");\n            }\n            if (!cachedClasses.get().containsKey(name)) {\n                throw new IllegalStateException(\"Extension name \" + name + \" doesn't exist (Extension \" + type + \")!\");\n            }\n\n            cachedNames.put(clazz, name);\n            cachedClasses.get().put(name, clazz);\n            cachedInstances.remove(name);\n        } else {\n            if (cachedAdaptiveClass == null) {","sourceCodeStart":675,"sourceCodeEnd":711,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java#L675-L711","documentation":"Thrown by ExtensionLoader.replaceExtension(String name, Class<?> clazz) when the provided class does not implement the SPI interface type. This is the same assignability guard as in addExtension but for the replace path. replaceExtension is marked @Deprecated and intended for test use only.","triggerScenarios":"Calling replaceExtension with a class that is not assignable to the SPI interface type. For example, replacing a Protocol extension with a class that only implements Filter. The check uses type.isAssignableFrom(clazz).","commonSituations":"Developer mistakenly uses the wrong ExtensionLoader instance (for a different SPI type). After refactoring, the replacement class no longer implements the required interface. Copy-paste from addExtension code without adjusting the class.","solutions":["Ensure the replacement class implements the SPI interface managed by this ExtensionLoader.","Verify you are calling replaceExtension on the correct ExtensionLoader (the right type).","Since replaceExtension is deprecated, prefer addExtension with a unique name or SPI config files."],"exampleFix":"// before — wrong class type\nprotocolLoader.replaceExtension(\"dubbo\", WrongImpl.class);\n\n// after\nclass CustomDubboProtocol implements Protocol { ... }\nprotocolLoader.replaceExtension(\"dubbo\", CustomDubboProtocol.class);","handlingStrategy":"type-guard","validationCode":"if (!type.isAssignableFrom(clazz)) {\n    throw new IllegalStateException(\n        clazz + \" must implement \" + type.getName());\n}\nloader.replaceExtension(name, clazz);","typeGuard":"static boolean implementsSpi(Class<?> implClass, Class<?> spiType) {\n    return implClass != null && spiType != null && spiType.isAssignableFrom(implClass);\n}","tryCatchPattern":null,"preventionTips":["Verify assignability before calling replaceExtension.","Note that replaceExtension is deprecated — prefer SPI config files or addExtension for production code.","Ensure the replacement class is for the correct SPI type."],"tags":["dubbo-spi","type-validation","registration","deprecated","extension-system"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}