{"record":{"id":"6368dad55082b69f","repo":"spring-projects/spring-boot","slug":"multiple-tagname-nodes-found","errorCode":null,"errorMessage":"Multiple '{tagName}' nodes found","messagePattern":"Multiple '(.+?)' nodes found","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/CustomLayersProvider.java","lineNumber":167,"sourceCode":"\tprivate List<String> getChildNodeTextContent(Element element, String tagName) {\n\t\tList<String> patterns = new ArrayList<>();\n\t\tNodeList nodes = element.getElementsByTagName(tagName);\n\t\tfor (int i = 0; i < nodes.getLength(); i++) {\n\t\t\tNode node = nodes.item(i);\n\t\t\tif (node instanceof Element) {\n\t\t\t\tpatterns.add(node.getTextContent());\n\t\t\t}\n\t\t}\n\t\treturn patterns;\n\t}\n\n\tprivate @Nullable Element getChildElement(Element element, String tagName) {\n\t\tNodeList nodes = element.getElementsByTagName(tagName);\n\t\tif (nodes.getLength() == 0) {\n\t\t\treturn null;\n\t\t}\n\t\tif (nodes.getLength() > 1) {\n\t\t\tthrow new IllegalStateException(\"Multiple '\" + tagName + \"' nodes found\");\n\t\t}\n\t\treturn (Element) nodes.item(0);\n\t}\n\n}\n","sourceCodeStart":149,"sourceCodeEnd":173,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/CustomLayersProvider.java#L149-L173","documentation":"IllegalStateException thrown by CustomLayersProvider.getChildElement when getElementsByTagName returns more than one match for a tag that is expected to appear at most once under a given parent. The schema may permit multiple siblings generally, but specific structural elements (e.g., a single <application> or <dependencies> root child) are required to be unique.","triggerScenarios":"Two or more elements with the same tagName under a parent where getChildElement expects a singleton. The method explicitly checks nodes.getLength() > 1 and aborts.","commonSituations":"Copy-pasting a <dependencies> block twice inside <layers>; merging two layers.xml files incorrectly; an automated generator emitting duplicate sections; misunderstanding the schema and adding multiple <application> roots.","solutions":["Open your layers.xml and locate the tagName named in the message; remove all but one occurrence.","Re-run schema validation — duplicates often also trip the XSD, but this guard fires first for non-uniqueness constraints.","If you genuinely need multiple selections, place them as sibling <into> elements inside a single parent, not as duplicate parents."],"exampleFix":"// before: <layers><application>...</application><application>...</application></layers>\n// after:  <layers><application><into layer=\"a\">...</into><into layer=\"b\">...</into></application></layers>","handlingStrategy":"validation","validationCode":"// Reject duplicate singleton elements before invoking the goal:\nSet<String> singletons = Set.of(\"application\", \"dependencies\"); // adjust per schema\nfor (String tag : singletons) {\n    if (root.getElementsByTagName(tag).getLength() > 1) {\n        throw new IllegalStateException(\"Duplicate '\" + tag + \"' in layers.xml\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    // invoke goal\n} catch (IllegalStateException ex) {\n    if (ex.getMessage().startsWith(\"Multiple '\") && ex.getMessage().endsWith(\"' nodes found\")) {\n        // remove the duplicate element named in the message\n    }\n    throw ex;\n}","preventionTips":["Treat <application>/<dependencies> as singletons; nest <into> for multiple selections.","Lint layers.xml in CI with a structural check.","Avoid merging layers.xml files by hand."],"tags":["spring-boot","maven-plugin","layers","xml","validation"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}