{"record":{"id":"a22dee6292a26006","repo":"MyCATApache/Mycat-Server","slug":"tagname-elements-length-over-one","errorCode":null,"errorMessage":"${tagName} elements length  over one!","messagePattern":"(.+?) elements length  over one!","errorType":"exception","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/config/util/ConfigUtil.java","lineNumber":134,"sourceCode":"    }\n\n    public static Map<String, Object> loadAttributes(Element e) {\n        Map<String, Object> map = new HashMap<String, Object>();\n        NamedNodeMap nm = e.getAttributes();\n        for (int j = 0; j < nm.getLength(); j++) {\n            Node n = nm.item(j);\n            if (n instanceof Attr) {\n                Attr attr = (Attr) n;\n                map.put(attr.getName(), attr.getNodeValue());\n            }\n        }\n        return map;\n    }\n\n    public static Element loadElement(Element parent, String tagName) {\n        NodeList nodeList = parent.getElementsByTagName(tagName);\n        if (nodeList.getLength() > 1) {\n            throw new ConfigException(tagName + \" elements length  over one!\");\n        }\n        if (nodeList.getLength() == 1) {\n            return (Element) nodeList.item(0);\n        } else {\n            return null;\n        }\n    }\n\n    /**\n     * 获取节点下所有property\n     * @param parent\n     * @return key-value property键值对\n     */\n    public static Map<String, Object> loadElements(Element parent) {\n        Map<String, Object> map = new HashMap<String, Object>();\n        NodeList children = parent.getChildNodes();\n        for (int i = 0; i < children.getLength(); i++) {\n            Node node = children.item(i);","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/util/ConfigUtil.java#L116-L152","documentation":"ConfigUtil.loadElement expects at most one XML element with the given tagName under the parent. If getElementsByTagName returns more than one match, it throws ConfigException because the result would be ambiguous. This enforces single-element semantics for config sections.","triggerScenarios":"Calling loadElement(parent, tagName) where the parsed XML document contains two or more sibling (or descendant) elements with that tag name.","commonSituations":"Duplicated XML stanzas in server.xml/schema.xml from a bad merge or accidental copy-paste (e.g. two <user> or two <system> blocks); generating config with a template loop that emitted a section twice.","solutions":["Open the XML file and remove or merge the duplicate '<tagName>' elements so only one remains","Identify the file/section by the tagName reported in the message","If duplicates are legitimate, change the loader code to iterate the NodeList instead of using loadElement"],"exampleFix":"<!-- before -->\n<user name=\"a\"/><user name=\"b\"/>\n<!-- after -->\n<user name=\"a\"/>  <!-- keep only one -->","handlingStrategy":"validation","validationCode":"NodeList nl = parent.getElementsByTagName(tagName);\nif (nl.getLength() > 1) throw new ConfigException(\"duplicate <\" + tagName + \"> found; keep exactly one\");","typeGuard":null,"tryCatchPattern":"try { Element e = ConfigUtil.loadElement(parent, tag); } catch (ConfigException e) { log.error(\"config has duplicates for <{}>\", tag); throw e; }","preventionTips":["Run xmllint or a schema validation to catch duplicate elements before load","Avoid merge tools duplicating XML stanzas; review config diffs","Keep one canonical definition per config section"],"tags":["config","xml","duplicate"],"backgroundTag":"schema-validation-failed","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}