spring-projects/spring-boot · error · IllegalStateException

Multiple '{}' nodes found

Error message

Multiple '{}' nodes found

What it means

Thrown by CustomLayersProvider.getChildElement as an IllegalStateException when getElementsByTagName(tagName) returns more than one matching child for a node that must be unique. The method is used for top-level singleton elements of layers.xml — application, dependencies, and layerOrder — so the error means the document contains duplicates of one of those. tagName is interpolated into the message so the offending element name is shown.

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 5b2dbdbb8b)

Solutions

  1. Open layers.xml and search for the element named in the message — there will be two.
  2. Remove the duplicate so only one <application>, <dependencies>, and <layerOrder> remains.
  3. Validate the file against layers.xsd after editing.
  4. Use a diff against a known-good layers.xml to spot the duplication.

Example fix

// before
<layers>
  <application>...</application>
  <application>...</application>
  <layerOrder>...</layerOrder>
</layers>
// after
<layers>
  <application>...</application>
  <layerOrder>...</layerOrder>
</layers>
Defensive patterns

Strategy: validation

Validate before calling

// Ensure singleton elements appear at most once in layers.xml
import org.w3c.dom.Document, Element;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;

void assertSingletons(File layersXml, String... names) throws Exception {
    Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(layersXml);
    Element root = d.getDocumentElement();
    for (String n : names) {
        int c = root.getElementsByTagName(n).getLength();
        if (c > 1) throw new IllegalStateException("Duplicate '" + n + "' nodes: " + c);
    }
}

Prevention

When it happens

Trigger: A layers.xml with two <application> blocks, two <dependencies> blocks, or two <layerOrder> blocks; copy-paste errors where a block was duplicated; merging two layers.xml files without removing duplicates.

Common situations: Hand-editing and accidentally duplicating a section; merging contributions from multiple modules into one layers.xml; outdated tutorial content combined with existing config.

Related errors


AI-assisted analysis of spring-projects/spring-boot@5b2dbdbb8b (2026-08-04). Data as JSON: /data/errors/6f76697bc7866ee5.json. Report an issue: GitHub.