MyCATApache/Mycat-Server · error · ConfigException
elements length over one!
Error message
${tagName} elements length over one! What it means
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.
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
Example fix
<!-- before --> <user name="a"/><user name="b"/> <!-- after --> <user name="a"/> <!-- keep only one -->
Defensive patterns
Strategy: validation
Validate before calling
NodeList nl = parent.getElementsByTagName(tagName);
if (nl.getLength() > 1) throw new ConfigException("duplicate <" + tagName + "> found; keep exactly one"); Try / catch
try { Element e = ConfigUtil.loadElement(parent, tag); } catch (ConfigException e) { log.error("config has duplicates for <{}>", tag); throw e; } Prevention
- 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
When it happens
Trigger: Calling loadElement(parent, tagName) where the parsed XML document contains two or more sibling (or descendant) elements with that tag name.
Common situations: 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.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- elements length over one!
- ConfigException wrapping cause (no message)
- dataHost name duplicated!
- dataNode reference dataHost: not exists!
- dataNode define error ,attribute can't be empty
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/a22dee6292a26006.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/config/util/ConfigUtil.java:134
}
public static Map<String, Object> loadAttributes(Element e) {
Map<String, Object> map = new HashMap<String, Object>();
NamedNodeMap nm = e.getAttributes();
for (int j = 0; j < nm.getLength(); j++) {
Node n = nm.item(j);
if (n instanceof Attr) {
Attr attr = (Attr) n;
map.put(attr.getName(), attr.getNodeValue());
}
}
return map;
}
public static Element loadElement(Element parent, String tagName) {
NodeList nodeList = parent.getElementsByTagName(tagName);
if (nodeList.getLength() > 1) {
throw new ConfigException(tagName + " elements length over one!");
}
if (nodeList.getLength() == 1) {
return (Element) nodeList.item(0);
} else {
return null;
}
}
/**
* 获取节点下所有property
* @param parent
* @return key-value property键值对
*/
public static Map<String, Object> loadElements(Element parent) {
Map<String, Object> map = new HashMap<String, Object>();
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);View on GitHub (pinned to 65f8d8beb7)