apache/maven · error · XMLStreamException
Unable to parse element '{}', must be a short integer
Error message
Unable to parse element '{}', must be a short integer What it means
Thrown by the Modello-generated StAX reader (template src/mdo/reader.vm) when a model XML field typed as short cannot be parsed by Short.valueOf(String). getShortValue in strict mode converts the NumberFormatException into a javax.xml.stream.XMLStreamException ('must be a short integer'); non-strict mode returns 0. Only models that declare short fields can trigger it.
Source
Thrown at src/mdo/reader.vm:1022
/**
* 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 {
if (s != null) {
try {
return Short.valueOf(s).shortValue();
} catch (NumberFormatException nfe) {
if (strict) {
throw new XMLStreamException("Unable to parse element '" + attribute + "', must be a short integer", parser.getLocation(), nfe);
}
}
}
return 0;
} //-- short getShortValue(String, String, XMLStreamReader, boolean)
/**
* Method getTrimmedValue.
*
* @param s a s object.
* @return String
*/
private String getTrimmedValue(String s) {
if (s != null) {
s = s.trim();
}
return s;
} //-- String getTrimmedValue(String)View on GitHub (pinned to e4093d4e12)
Solutions
- Set the offending value within the short range (-32768..32767).
- If the value legitimately exceeds short range, move to an int/long field in the model and regenerate the reader.
- Use strict=false when defaulting to 0 is acceptable.
- Validate config values with a schema or unit test before writing the file.
Example fix
<!-- before --> <port>99999</port> <!-- after --> <port>32767</port>
Defensive patterns
Strategy: validation
Validate before calling
static boolean inShortRange(int v) { return v >= Short.MIN_VALUE && v <= Short.MAX_VALUE; } Try / catch
try {
reader.read(in, true);
} catch (XMLStreamException e) {
// message names field; fix data or downgrade to strict=false
} Prevention
- Range-check config values before writing them to model files.
- If ranges may grow, model the field as int from the start.
When it happens
Trigger: Strict read of a model XML where a short field contains text like 'abc', is empty, or exceeds -32768..32767 (e.g. a port or count field set to 99999).
Common situations: Port/count fields overflowing after config changes; hand-edited files with typos; producers not validating ranges on write.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Unable to parse element '{}', must be a byte
- Unable to parse element '{}', must be a floating point numbe
- Unable to parse element '{}', must be an integer
- Unable to parse element '{}', must be a long integer
- Expected root element '${rootTag}' but found '{}'
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/b21facc78b82df02.
Report an issue: GitHub.