spring-projects/spring-boot · error · IllegalStateException
Multiple '{tagName}' nodes found
Error message
Multiple '{tagName}' nodes found What it means
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.
Source
Thrown at build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/CustomLayersProvider.java:167
private List<String> getChildNodeTextContent(Element element, String tagName) {
List<String> patterns = new ArrayList<>();
NodeList nodes = element.getElementsByTagName(tagName);
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node instanceof Element) {
patterns.add(node.getTextContent());
}
}
return patterns;
}
private @Nullable Element getChildElement(Element element, String tagName) {
NodeList nodes = element.getElementsByTagName(tagName);
if (nodes.getLength() == 0) {
return null;
}
if (nodes.getLength() > 1) {
throw new IllegalStateException("Multiple '" + tagName + "' nodes found");
}
return (Element) nodes.item(0);
}
}
View on GitHub (pinned to 270dfe353f)
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.
Example fix
// before: <layers><application>...</application><application>...</application></layers> // after: <layers><application><into layer="a">...</into><into layer="b">...</into></application></layers>
Defensive patterns
Strategy: validation
Validate before calling
// Reject duplicate singleton elements before invoking the goal:
Set<String> singletons = Set.of("application", "dependencies"); // adjust per schema
for (String tag : singletons) {
if (root.getElementsByTagName(tag).getLength() > 1) {
throw new IllegalStateException("Duplicate '" + tag + "' in layers.xml");
}
} Try / catch
try {
// invoke goal
} catch (IllegalStateException ex) {
if (ex.getMessage().startsWith("Multiple '") && ex.getMessage().endsWith("' nodes found")) {
// remove the duplicate element named in the message
}
throw ex;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to process custom layers configuration {source}
- Invalid layers.xml configuration
- Failed to load layers configuration with name '%s': '%s' not
- Unable to load layers XSD
- Could not build classpath
AI-assisted analysis of spring-projects/spring-boot@270dfe353f (2026-08-11).
Data as JSON: /api/errors/6368dad55082b69f.
Report an issue: GitHub.