{"record":{"id":"848de2fbf982dc30","repo":"apache/maven","slug":"missing-required-value-for-attribute","errorCode":null,"errorMessage":"Missing required value for attribute '{}'","messagePattern":"Missing required value for attribute '(.+?)'","errorType":"exception","errorClass":"XMLStreamException","httpStatus":null,"severity":"error","filePath":"src/mdo/reader.vm","lineNumber":998,"sourceCode":"        return 0;\n    } //-- long getLongValue(String, String, XMLStreamReader, boolean)\n\n    /**\n     * Method getRequiredAttributeValue.\n     *\n     * @param s a s object.\n     * @param strict a strict object.\n     * @param parser a parser object.\n     * @param attribute a attribute object.\n     * @throws XMLStreamException XMLStreamException if\n     * any.\n     * @return String\n     */\n    private String getRequiredAttributeValue(String s, String attribute, XMLStreamReader parser, boolean strict)\n            throws XMLStreamException {\n        if (s == null) {\n            if (strict) {\n                throw new XMLStreamException(\"Missing required value for attribute '\" + attribute + \"'\", parser.getLocation(), null);\n            }\n        }\n        return s;\n    } //-- String getRequiredAttributeValue(String, String, XMLStreamReader, boolean)\n\n    /**\n     * Method getShortValue.\n     *\n     * @param s a s object.\n     * @param strict a strict object.\n     * @param parser a parser object.\n     * @param attribute a attribute object.\n     * @throws XMLStreamException XMLStreamException if\n     * any.\n     * @return short\n     */\n    private short getShortValue(String s, String attribute, XMLStreamReader parser, boolean strict)\n            throws XMLStreamException {","sourceCodeStart":980,"sourceCodeEnd":1016,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/src/mdo/reader.vm#L980-L1016","documentation":"Thrown by the Modello-generated StAX reader (template src/mdo/reader.vm) from getRequiredAttributeValue when an element declares a required attribute that is absent (attribute value is null). In strict mode this aborts parsing with javax.xml.stream.XMLStreamException; non-strict mode returns null for the attribute and parsing continues, which may surface later as an NPE or validation error downstream.","triggerScenarios":"Reading a model XML document in strict mode where an element carrying required attributes (per the mdo model, e.g. activationFile/property names, repository ids in some model versions) omits one, such as <file missing='the required one'/> or <activeByDefault/> without its id attribute.","commonSituations":"Documents written by older model versions that did not require the attribute; hand-authored XML missing mandatory attributes; elements refactored to add a new required attribute without regenerating the XML; whitespace-stripped attributes reduced to empty strings.","solutions":["Compare the element against the model schema/xdoc and add the missing required attribute with a valid value.","Upgrade the producer (plugin/tool) that writes the file to a version matching the model the reader enforces.","Regenerate the document from its source instead of hand-editing.","If optional semantics are wanted, read with strict=false, then apply your own defaults for null attributes."],"exampleFix":"<!-- before -->\n<ruleset>\n  <requireJavaVersion/>\n</ruleset>\n<!-- after (attribute now required by model) -->\n<requireJavaVersion version=\"[17,)\"/>","handlingStrategy":"validation","validationCode":"// before parse: schema-validate so required attributes are checked up front\nSchemaFactory f = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);\nValidator v = f.newSchema(new StreamSource(modelXsd)).newValidator();\nv.setErrorHandler(failFastHandler);\nv.validate(new StreamSource(xmlFile));","typeGuard":null,"tryCatchPattern":"try {\n    reader.read(in, true);\n} catch (XMLStreamException e) {\n    if (e.getMessage().startsWith(\"Missing required value\")) { /* report authoring error */ }\n}","preventionTips":["Validate documents against the model schema in CI.","When bumping model versions, regenerate sample/template XML.","Prefer strict mode in authoring pipelines to catch omissions early."],"tags":["xml","stax","modello","required-attribute","schema-validation"],"backgroundTag":"missing-required-xml-attribute","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}