{"record":{"id":"98deacd6e3be940a","repo":"apache/maven","slug":"unrecognised-tag","errorCode":null,"errorMessage":"Unrecognised tag: '{}'","messagePattern":"Unrecognised tag: '(.+?)'","errorType":"exception","errorClass":"XMLStreamException","httpStatus":null,"severity":"error","filePath":"src/mdo/reader-stax.vm","lineNumber":610,"sourceCode":"    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;) {\n            int eventType = nextTag(parser);\n            if (eventType == XMLStreamReader.START_ELEMENT) {\n                unrecognizedTagCount++;\n            } else if (eventType == XMLStreamReader.END_ELEMENT) {\n                unrecognizedTagCount--;\n            }\n        }\n    } //-- void checkUnknownElement(XMLStreamReader, boolean)\n\n    /**\n     * Method getTrimmedValue.\n     *\n     * @param s a s object.\n     * @return String\n     */","sourceCodeStart":592,"sourceCodeEnd":628,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/src/mdo/reader-stax.vm#L592-L628","documentation":"checkUnknownElement(parser, strict) is called when a child element matches no field of the class being parsed. Strict mode throws with the element's QName (parser.getName()). In lenient mode the same method silently skips the entire unrecognized subtree using a depth counter (unrecognizedTagCount via nextTag), so non-strict reads drop unknown content instead of failing.","triggerScenarios":"Strict read of documents containing elements unknown to the reader's model: a pom using a feature newer than the reader, misspelled tags like <dependencys>, or custom extension elements the model does not define.","commonSituations":"Version skew between document schema and generated reader; hand-editing typos; third-party tools injecting proprietary elements into documents.","solutions":["Fix or remove the unrecognized element - the message and location give its name and position.","Upgrade the library so its generated model knows the element.","Check spelling and casing against the model documentation.","If unknown elements must be tolerated, read with strict=false - they and their subtrees are skipped."],"exampleFix":"<!-- before -->\n<project xmlns=\"http://maven.apache.org/POM/4.0.0\">\n  <dependencys>...</dependencys>\n</project>\n\n<!-- after -->\n<project xmlns=\"http://maven.apache.org/POM/4.0.0\">\n  <dependencies>...</dependencies>\n</project>","handlingStrategy":"fallback","validationCode":"// XSD validation reports unknown elements before the strict 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":"static boolean isUnknownElement(XMLStreamException e) {\n    return e.getMessage() != null && e.getMessage().startsWith(\"Unrecognised tag\");\n}","tryCatchPattern":"byte[] bytes = in.readAllBytes();\ntry {\n    Model model = reader.read(new ByteArrayInputStream(bytes), true);\n} catch (XMLStreamException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Unrecognised tag\")) {\n        // tolerate unknown subtrees: re-parse leniently, unknown elements are skipped\n        Model model = reader.read(new ByteArrayInputStream(bytes), false);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Keep document schema versions and the reader's library version aligned.","Validate against the XSD before strict reads.","Reject documents from unknown producers at intake."],"tags":["xml","stax","unknown-element","strict-mode","schema-validation"],"backgroundTag":"xml-unknown-element","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}