{"record":{"id":"c5276f7ee225e8a3","repo":"apache/maven","slug":"duplicated-tag","errorCode":null,"errorMessage":"Duplicated tag: '{}'","messagePattern":"Duplicated tag: '(.+?)'","errorType":"exception","errorClass":"XMLStreamException","httpStatus":null,"severity":"error","filePath":"src/mdo/reader-stax.vm","lineNumber":570,"sourceCode":"#end\n#if ( ! ${aliases.isEmpty()} )\n        switch (tagName) {\n  #foreach( $entry in $aliases.entrySet() )\n        case \"${entry.key}\":\n            tagName = \"${entry.value}\";\n            break;\n  #end\n        }\n#end\n#if ( ! ${flats.isEmpty()} )\n        switch (tagName) {\n  #foreach( $entry in $flats.entrySet() )\n        case \"${entry.key}\":\n  #end\n            break;\n        default:\n            if (!parsed.add(tagName)) {\n                throw new XMLStreamException(\"Duplicated tag: '\" + tagName + \"'\", parser.getLocation(), null);\n            }\n        }\n#else\n        if (!parsed.add(tagName)) {\n            throw new XMLStreamException(\"Duplicated tag: '\" + tagName + \"'\", parser.getLocation(), null);\n        }\n#end\n        return tagName;\n    }\n\n    /**\n     * Method checkUnknownAttribute.\n     *\n     * @param parser a parser object.\n     * @param strict a strict object.\n     * @param tagName a tagName object.\n     * @param attribute a attribute object.\n     * @throws XMLStreamException XMLStreamException if","sourceCodeStart":552,"sourceCodeEnd":588,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/src/mdo/reader-stax.vm#L552-L588","documentation":"checkDuplicate(tagName, parser, parsed) tracks recognized child element names of each parsed class in a Set. In models that declare flat mappings, the flat tags pass through a switch untouched; every other tag reaches the default branch, which throws when parsed.add(tagName) returns false - that child element already occurred under the same parent. It enforces single-occurrence (non-list) fields in both strict and lenient mode.","triggerScenarios":"Reading a document where a singular field's element repeats inside its parent: two <groupId> in one <dependency>, two <packaging> or two <description> under <project> - thrown even when strict=false.","commonSituations":"Copy-paste editing in pom.xml; merge conflicts resolved by keeping both blocks; generators emitting an element twice inside one parent.","solutions":["Use the exception's location (line/column) to find the second occurrence and delete one of the duplicates.","Validate the document against its XSD first - maxOccurs=1 violations get clearer diagnostics.","If repetition is genuinely needed, the model must define the field as a list - a model change and regeneration, not a runtime fix."],"exampleFix":"<!-- before -->\n<dependency>\n  <groupId>org.apache.maven</groupId>\n  <groupId>com.example</groupId>\n  <artifactId>app</artifactId>\n</dependency>\n\n<!-- after -->\n<dependency>\n  <groupId>com.example</groupId>\n  <artifactId>app</artifactId>\n</dependency>","handlingStrategy":"try-catch","validationCode":"// Schema-validate before the model reader: duplicates surface as maxOccurs violations\nSchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);\nValidator v = sf.newSchema(new StreamSource(pomXsdFile)).newValidator();\nv.validate(new StreamSource(pomFile)); // throws SAXException with precise position","typeGuard":null,"tryCatchPattern":"try {\n    Model model = reader.read(in, true);\n} catch (XMLStreamException e) {\n    Location loc = e.getLocation();\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Duplicated tag\")) {\n        log.warn(\"duplicate element at line {} column {}\", loc.getLineNumber(), loc.getColumnNumber());\n    }\n    throw e;\n}","preventionTips":["Validate against the XSD in CI before modello readers touch the file.","Use XML-aware editors that flag duplicate singular elements.","After merge conflicts, check siblings for repeated tags."],"tags":["xml","stax","duplicate-element","parsing","modello"],"backgroundTag":"xml-duplicate-element","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}