{"record":{"id":"9a21afdc908b92fe","repo":"apache/maven","slug":"duplicated-tag-9a21af","errorCode":null,"errorMessage":"Duplicated tag: '{}'","messagePattern":"Duplicated tag: '(.+?)'","errorType":"exception","errorClass":"XMLStreamException","httpStatus":null,"severity":"error","filePath":"src/mdo/reader.vm","lineNumber":634,"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     * Sets the state of the \"add default entities\" flag.\n     *\n     * @param addDefaultEntities a addDefaultEntities object.\n     */\n    public void setAddDefaultEntities(boolean addDefaultEntities) {\n        this.addDefaultEntities = addDefaultEntities;\n    } //-- void setAddDefaultEntities(boolean)","sourceCodeStart":616,"sourceCodeEnd":652,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/src/mdo/reader.vm#L616-L652","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copy-paste editing; merges keeping both blocks; generators appending a field twice.","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."],"exampleFix":"<!-- before -->\n<project xmlns=\"http://maven.apache.org/POM/4.0.0\">\n  <packaging>jar</packaging>\n  <packaging>war</packaging>\n</project>\n\n<!-- after -->\n<project xmlns=\"http://maven.apache.org/POM/4.0.0\">\n  <packaging>war</packaging>\n</project>","handlingStrategy":"try-catch","validationCode":"// XSD validation catches duplicate singular elements before the model read\nSchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);\nsf.newSchema(new StreamSource(xsdFile)).newValidator().validate(new StreamSource(xmlFile));","typeGuard":null,"tryCatchPattern":"try {\n    Model model = reader.read(in, true);\n} catch (XMLStreamException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Duplicated tag\")) {\n        // report e.getLocation() with the file name\n    }\n    throw e;\n}","preventionTips":["Schema-validate documents in CI.","Use editors that flag duplicate singular siblings.","Review merged blocks 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"}