apache/maven · error · XMLStreamException
Duplicated tag: '{}'
Error message
Duplicated tag: '{}' What it means
checkDuplicate in the classic reader.vm template, flats branch: recognized child tags that are not flat mappings reach the switch default, where parsed.add(tagName) returning false (tag already seen under this parent) throws. It enforces single-occurrence fields regardless of strict mode, in readers generated without the newer template's extras.
Source
Thrown at src/mdo/reader.vm:634
#end
#if ( ! ${aliases.isEmpty()} )
switch (tagName) {
#foreach( $entry in $aliases.entrySet() )
case "${entry.key}":
tagName = "${entry.value}";
break;
#end
}
#end
#if ( ! ${flats.isEmpty()} )
switch (tagName) {
#foreach( $entry in $flats.entrySet() )
case "${entry.key}":
#end
break;
default:
if (!parsed.add(tagName)) {
throw new XMLStreamException("Duplicated tag: '" + tagName + "'", parser.getLocation(), null);
}
}
#else
if (!parsed.add(tagName)) {
throw new XMLStreamException("Duplicated tag: '" + tagName + "'", parser.getLocation(), null);
}
#end
return tagName;
}
/**
* Sets the state of the "add default entities" flag.
*
* @param addDefaultEntities a addDefaultEntities object.
*/
public void setAddDefaultEntities(boolean addDefaultEntities) {
this.addDefaultEntities = addDefaultEntities;
} //-- void setAddDefaultEntities(boolean)View on GitHub (pinned to e4093d4e12)
Solutions
- Remove the duplicate element; the exception location identifies the second occurrence.
- Schema-validate first for clearer maxOccurs diagnostics.
- Model-level fix (list field) required if repetition is legitimate.
Example fix
<!-- before --> <project xmlns="http://maven.apache.org/POM/4.0.0"> <packaging>jar</packaging> <packaging>war</packaging> </project> <!-- after --> <project xmlns="http://maven.apache.org/POM/4.0.0"> <packaging>war</packaging> </project>
Defensive patterns
Strategy: try-catch
Validate before calling
// XSD validation catches duplicate singular elements before the model read SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); sf.newSchema(new StreamSource(xsdFile)).newValidator().validate(new StreamSource(xmlFile));
Try / catch
try {
Model model = reader.read(in, true);
} catch (XMLStreamException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Duplicated tag")) {
// report e.getLocation() with the file name
}
throw e;
} Prevention
- Schema-validate documents in CI.
- Use editors that flag duplicate singular siblings.
- Review merged blocks for repeated tags.
When it happens
Trigger: A singular child element repeated inside its parent: two <packaging> under <project>, two <systemPath> in one dependency, two <name> in the same element - thrown in strict and lenient reads alike.
Common situations: Copy-paste editing; merges keeping both blocks; generators appending a field twice.
Related errors
- Duplicated tag: '{}'
- Expected root element '${rootTag}' but found '{}'
- Expected root element '${rootTag}' but found '{}'
- Duplicated tag: '${rootTag}'
- Expected root element '${rootTag}' but found no element at a
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/9a21afdc908b92fe.
Report an issue: GitHub.