{"record":{"id":"14c68c93ee86ccc5","repo":"apache/dubbo","slug":"found-more-than-one-config-by-name-name-instan","errorCode":null,"errorMessage":"Found more than one config by name: <name>, instances: <list>. Please remove redundant configs or get config by id.","messagePattern":"Found more than one config by name: <name>, instances: <list>\\. Please remove redundant configs or get config by id\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java","lineNumber":359,"sourceCode":"    /**\n     * Get config by name if existed\n     *\n     * @param cls\n     * @param name\n     * @return\n     */\n    protected <C extends AbstractConfig> C getConfigByName(Class<? extends C> cls, String name) {\n        Map<String, ? extends C> configsMap = getConfigsMap(cls);\n        if (configsMap.isEmpty()) {\n            return null;\n        }\n        // try to find config by name\n        if (ReflectUtils.hasMethod(cls, CONFIG_NAME_READ_METHOD)) {\n            List<C> list = configsMap.values().stream()\n                    .filter(cfg -> name.equals(getConfigName(cfg)))\n                    .collect(Collectors.toList());\n            if (list.size() > 1) {\n                throw new IllegalStateException(\"Found more than one config by name: \" + name + \", instances: \" + list\n                        + \". Please remove redundant configs or get config by id.\");\n            } else if (list.size() == 1) {\n                return list.get(0);\n            }\n        }\n        return null;\n    }\n\n    private <C extends AbstractConfig> String getConfigName(C config) {\n        try {\n            return ReflectUtils.getProperty(config, CONFIG_NAME_READ_METHOD);\n        } catch (Exception e) {\n            return null;\n        }\n    }\n\n    protected <C extends AbstractConfig> Optional<C> findConfigByValue(Collection<C> values, C config) {\n        // 1. find same config instance (speed up raw api usage)","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java#L341-L377","documentation":"Thrown by AbstractConfigManager.getConfigByName() when a name lookup (via the 'name' property, read through CONFIG_NAME_READ_METHOD) returns more than one config of the same type. Unlike id-based lookup, name-based lookup is ambiguous when two configs share a name, so Dubbo refuses to pick one arbitrarily.","triggerScenarios":"Two configs of the same type (e.g. two RegistryConfig) both having name=\"myRegistry\", then looking up by that name. Setting the same 'name' on multiple bean definitions.","commonSituations":"Reusing a friendly name across multiple registry/protocol configs. Spring bean definitions where name (not id) collides. Copy-pasting config blocks and forgetting to rename.","solutions":["Give each config a unique 'name' (or rely on unique ids).","Look up the config by id instead of name when ambiguity is possible.","Merge the duplicate configs into one."],"exampleFix":"<!-- before -->\n<dubbo:registry name=\"main\" address=\"zk1\"/>\n<dubbo:registry name=\"main\" address=\"zk2\"/>\n<!-- after -->\n<dubbo:registry id=\"r1\" name=\"main1\" address=\"zk1\"/>\n<dubbo:registry id=\"r2\" name=\"main2\" address=\"zk2\"/>","handlingStrategy":"validation","validationCode":"// Before name lookup, ensure the name is unique across the type\nString name = \"main\";\nList<? extends RegistryConfig> matches = configManager.getConfigs(RegistryConfig.class).stream()\n    .filter(c -> name.equals(c.getName()))\n    .collect(Collectors.toList());\nif (matches.size() > 1) {\n    throw new IllegalStateException(\"Ambiguous name '\" + name + \"' across \" + matches);\n}\nconfigManager.getConfigByName(RegistryConfig.class, name);","typeGuard":"static <C extends AbstractConfig> boolean isNameUnique(ConfigManager cm, Class<C> cls, String name) {\n    long n = cm.getConfigs(cls).stream().filter(c -> name.equals(c.getName())).count();\n    return n <= 1;\n}","tryCatchPattern":"try {\n    cfg = configManager.getConfigByName(RegistryConfig.class, name);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Found more than one config by name\")) {\n        cfg = configManager.getConfig(RegistryConfig.class, id).orElse(null); // fall back to id\n    } else throw e;\n}","preventionTips":["Prefer id-based lookups over name-based when ambiguity is possible.","Enforce unique names within a config type.","Add a startup check that no two configs share a name."],"tags":["config","duplicate","name-lookup","ambiguity"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}