apache/maven · error · XMLStreamException
Missing required value for attribute '{}'
Error message
Missing required value for attribute '{}' What it means
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.
Source
Thrown at src/mdo/reader.vm:998
return 0;
} //-- long getLongValue(String, String, XMLStreamReader, boolean)
/**
* Method getRequiredAttributeValue.
*
* @param s a s object.
* @param strict a strict object.
* @param parser a parser object.
* @param attribute a attribute object.
* @throws XMLStreamException XMLStreamException if
* any.
* @return String
*/
private String getRequiredAttributeValue(String s, String attribute, XMLStreamReader parser, boolean strict)
throws XMLStreamException {
if (s == null) {
if (strict) {
throw new XMLStreamException("Missing required value for attribute '" + attribute + "'", parser.getLocation(), null);
}
}
return s;
} //-- String getRequiredAttributeValue(String, String, XMLStreamReader, boolean)
/**
* Method getShortValue.
*
* @param s a s object.
* @param strict a strict object.
* @param parser a parser object.
* @param attribute a attribute object.
* @throws XMLStreamException XMLStreamException if
* any.
* @return short
*/
private short getShortValue(String s, String attribute, XMLStreamReader parser, boolean strict)
throws XMLStreamException {View on GitHub (pinned to e4093d4e12)
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.
Example fix
<!-- before --> <ruleset> <requireJavaVersion/> </ruleset> <!-- after (attribute now required by model) --> <requireJavaVersion version="[17,)"/>
Defensive patterns
Strategy: validation
Validate before calling
// before parse: schema-validate so required attributes are checked up front SchemaFactory f = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Validator v = f.newSchema(new StreamSource(modelXsd)).newValidator(); v.setErrorHandler(failFastHandler); v.validate(new StreamSource(xmlFile));
Try / catch
try {
reader.read(in, true);
} catch (XMLStreamException e) {
if (e.getMessage().startsWith("Missing required value")) { /* report authoring error */ }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Expected root element '${rootTag}' but found '{}'
- Duplicated tag: '{}'
- Unrecognised tag: '{}'
- Expected root element '${rootTag}' but found '{}'
- Duplicated tag: '{}'
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/848de2fbf982dc30.
Report an issue: GitHub.