{"record":{"id":"7f281f11bb5fec2e","repo":"apache/maven","slug":"unknown-attribute-for-tag","errorCode":null,"errorMessage":"Unknown attribute '{}' for tag '{}'","messagePattern":"Unknown attribute '(.+?)' for tag '(.+?)'","errorType":"exception","errorClass":"XMLStreamException","httpStatus":null,"severity":"error","filePath":"src/mdo/reader-stax.vm","lineNumber":595,"sourceCode":"#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\n     * any.\n     * @throws IOException IOException if any.\n     */\n    private void checkUnknownAttribute(XMLStreamReader parser, String attribute, String tagName, boolean strict) throws XMLStreamException {\n        // strictXmlAttributes = true for model: if strict == true, not only elements are checked but attributes too\n        if (strict) {\n            throw new XMLStreamException(\"Unknown attribute '\" + attribute + \"' for tag '\" + tagName + \"'\", parser.getLocation(), null);\n        }\n    } //-- void checkUnknownAttribute(XMLStreamReader, String, String, boolean)\n\n    /**\n     * Method checkUnknownElement.\n     *\n     * @param parser a parser object.\n     * @param strict a strict object.\n     * @throws XMLStreamException XMLStreamException if\n     * any.\n     * @throws IOException IOException if any.\n     */\n    private void checkUnknownElement(XMLStreamReader parser, boolean strict) throws XMLStreamException {\n        if (strict) {\n            throw new XMLStreamException(\"Unrecognised tag: '\" + parser.getName() + \"'\", parser.getLocation(), null);\n        }\n\n        for (int unrecognizedTagCount = 1; unrecognizedTagCount > 0;) {","sourceCodeStart":577,"sourceCodeEnd":613,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/src/mdo/reader-stax.vm#L577-L613","documentation":"checkUnknownAttribute(parser, attribute, tagName, strict) runs for each attribute the parser reports on an element. With strict=true, any attribute the model does not define for that element is rejected - the template comment notes strictXmlAttributes: in strict mode attributes are checked too, not only elements. The message names both the attribute and its tag.","triggerScenarios":"read(parser, true) on an element carrying an undeclared attribute: a typo'd attribute name, an attribute that belongs to a different schema version, or tooling-injected custom attributes the model never declared.","commonSituations":"Hand-edited XML with typos; documents written for a newer schema than the reader knows; tools adding proprietary metadata attributes; copy-paste from examples of a different format.","solutions":["Remove the offending attribute or fix its spelling - the message names the attribute and the tag.","Check the model/XSD for the attributes allowed on that element and use only those.","Move custom metadata into an element the model defines (e.g. a properties entry) instead of an attribute.","Only if tolerating arbitrary attributes is acceptable, parse with strict=false."],"exampleFix":"<!-- before -->\n<dependency version=\"1.0\">\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  <version>1.0</version>\n</dependency>","handlingStrategy":"try-catch","validationCode":"// XSD validation flags undeclared attributes before the model read\nSchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);\nValidator v = sf.newSchema(new StreamSource(xsdFile)).newValidator();\nv.validate(new StreamSource(xmlFile));","typeGuard":null,"tryCatchPattern":"try {\n    Model model = reader.read(parser, true);\n} catch (XMLStreamException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Unknown attribute\")) {\n        // attribute not in the model: fix the document or decide to read leniently\n    }\n    throw e;\n}","preventionTips":["Author attributes only from the model's documented vocabulary.","Schema-validate before strict reads.","Prefer model-defined elements for custom metadata instead of attributes."],"tags":["xml","stax","attributes","strict-mode","validation"],"backgroundTag":"xml-unknown-attribute","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}