{"record":{"id":"59bd6e1f7ed86a2c","repo":"apache/dubbo","slug":"extension-name-name-already-exists-extension","errorCode":null,"errorMessage":"Extension name ${name} already exists (Extension ${type})!","messagePattern":"Extension name (.+?) already exists \\(Extension (.+?)\\)!","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java","lineNumber":665,"sourceCode":"     * @throws IllegalStateException when extension with the same name has already been registered.\n     */\n    public void addExtension(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 the 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 + \" already exists (Extension \" + type + \")!\");\n            }\n\n            cachedNames.put(clazz, name);\n            cachedClasses.get().put(name, clazz);\n        } else {\n            if (cachedAdaptiveClass != null) {\n                throw new IllegalStateException(\"Adaptive Extension already exists (Extension \" + type + \")!\");\n            }\n\n            cachedAdaptiveClass = clazz;\n        }\n    }\n\n    /**\n     * Replace the existing extension via API\n     *\n     * @param name  extension name\n     * @param clazz extension class","sourceCodeStart":647,"sourceCodeEnd":683,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java#L647-L683","documentation":"Thrown by ExtensionLoader.addExtension(String name, Class<?> clazz) when the provided name already exists in cachedClasses (the map of already-loaded extension names to classes). Each extension name within a single SPI type must be unique. This prevents accidental double-registration or conflicting implementations under the same name.","triggerScenarios":"Calling addExtension with a name that was already loaded from an SPI config file or previously registered via addExtension. For example, registering name=\"dubbo\" for a custom Protocol implementation when the built-in dubbo protocol already holds that name.","commonSituations":"Attempt to override a built-in extension using addExtension instead of replaceExtension. A test setup method called addExtension twice with the same name. A module is loaded twice (e.g., duplicate JAR on classpath) causing double registration.","solutions":["If you intend to override an existing extension, use replaceExtension(name, clazz) instead of addExtension.","Choose a different, unique name for your custom extension.","Check loader.getSupportedExtensions() before registering to see existing names."],"exampleFix":"// before — name conflict with built-in extension\nloader.addExtension(\"dubbo\", CustomProtocol.class); // 'dubbo' already exists\n\n// after — use replaceExtension to override, or a new name\nloader.replaceExtension(\"dubbo\", CustomProtocol.class);\n// or\nloader.addExtension(\"customDubbo\", CustomProtocol.class);","handlingStrategy":"validation","validationCode":"if (loader.hasExtension(name)) {\n    // use replaceExtension to override, or choose a different name\n    loader.replaceExtension(name, clazz);\n} else {\n    loader.addExtension(name, clazz);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check loader.hasExtension(name) or loader.getSupportedExtensions() before calling addExtension.","Use replaceExtension when you intend to override an existing extension.","Choose unique, descriptive extension names to avoid collisions."],"tags":["dubbo-spi","duplicate","registration","extension-system"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}