apache/maven · error · XMLStreamException
Unable to parse element '{}', must be a long integer
Error message
Unable to parse element '{}', must be a long integer What it means
Thrown by the Modello-generated StAX reader (template src/mdo/reader.vm) when a model XML field typed as long cannot be parsed by Long.valueOf(String). getLongValue in strict mode wraps the NumberFormatException in a javax.xml.stream.XMLStreamException ('must be a long integer'); non-strict mode returns 0L. Commonly hit on timestamp/size fields expressed in nanoseconds or epoch millis.
Source
Thrown at src/mdo/reader.vm:976
/**
* Method getLongValue.
*
* @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 long
*/
private long getLongValue(String s, String attribute, XMLStreamReader parser, boolean strict)
throws XMLStreamException {
if (s != null) {
try {
return Long.valueOf(s).longValue();
} catch (NumberFormatException nfe) {
if (strict) {
throw new XMLStreamException("Unable to parse element '" + attribute + "', must be a long integer", parser.getLocation(), nfe);
}
}
}
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)View on GitHub (pinned to e4093d4e12)
Solutions
- Fix the text at the reported location to a plain integer within long range.
- Remove grouping separators and unit suffixes from generated files.
- Re-fetch derived files instead of editing them.
- Fall back to strict=false when the 0 default is acceptable.
Example fix
<!-- before --> <size>1,048,576</size> <!-- after --> <size>1048576</size>
Defensive patterns
Strategy: validation
Validate before calling
static boolean isPlainLong(String s) { return s != null && s.matches("[+-]?\\d+") && s.length() < 19; } Try / catch
try {
reader.read(in, true);
} catch (XMLStreamException e) {
log.warn("bad long field at " + e.getLocation(), e);
} Prevention
- Strip grouping separators when importing values from spreadsheets.
- Store quantities without units in XML; interpret units in code.
When it happens
Trigger: Strict read of a model XML where a long field holds an empty string, a decimal like '1690000000000.5', a value with unit suffix '1024b', or digits with grouping commas.
Common situations: Hand-tuned metadata or config files with human-friendly but unparseable numbers; copy-paste of values from spreadsheets that insert thin spaces/commas; schema changes between model versions.
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 short integer
- Expected root element '${rootTag}' but found '{}'
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/ec23af47db91117c.
Report an issue: GitHub.