{"record":{"id":"96524d01f39afd0f","repo":"apache/maven","slug":"unknown-attribute-for-tag-96524d","errorCode":null,"errorMessage":"Unknown attribute '{}' for tag '{}'","messagePattern":"Unknown attribute '(.+?)' for tag '(.+?)'","errorType":"exception","errorClass":"XMLStreamException","httpStatus":null,"severity":"error","filePath":"src/mdo/reader.vm","lineNumber":702,"sourceCode":"        return true;\n    } //-- boolean checkFieldWithDuplicate(XMLStreamReader, String, String, Set<String>)\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)\n        throws XMLStreamException, IOException {\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)\n        throws XMLStreamException, IOException {\n        if (strict) {\n            throw new XMLStreamException(\"Unrecognised tag: '\" + parser.getLocalName() + \"'\", parser.getLocation(), null);\n        }\n","sourceCodeStart":684,"sourceCodeEnd":720,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/src/mdo/reader.vm#L684-L720","documentation":"checkUnknownAttribute in the classic reader.vm template, twin of the stax template's method: for every attribute the parser reports on an element, strict mode throws if the model does not declare it (the strictXmlAttributes comment applies here too). The method also declares IOException, but the throw itself is an XMLStreamException naming the attribute and tag.","triggerScenarios":"read(parser, true) over an element carrying an undeclared attribute: typo'd names, attributes from another schema version, or tool-injected custom attributes.","commonSituations":"Hand-edited XML with attribute typos; documents written for newer schemas read by older readers; tools adding metadata attributes the model never declared.","solutions":["Remove the attribute or correct its name - the message identifies both attribute and tag.","Check the model/XSD for allowed attributes on that element.","Encode custom metadata in a model-defined element instead.","Parse with strict=false only if arbitrary attributes are acceptable."],"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 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(parser, true);\n} catch (XMLStreamException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Unknown attribute\")) {\n        // fix the document, or decide on a lenient read\n    }\n    throw e;\n}","preventionTips":["Author attributes only from the model vocabulary.","Schema-validate before strict reads.","Keep custom data in model-defined elements."],"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"}