apache/maven · error · XMLStreamException

Unable to parse element '{}', must be an integer

Error message

Unable to parse element '{}', must be an integer

What it means

Thrown by the Modello-generated StAX reader (template src/mdo/reader.vm) when a model XML field typed as int contains text Integer.valueOf(String) cannot parse. In strict mode getIntegerValue rethrows as javax.xml.stream.XMLStreamException ('must be an integer') with element name and location; non-strict parsing falls back to the supplied defaultValue (typically 0).

Source

Thrown at src/mdo/reader.vm:951

    /**
     * Method getIntegerValue.
     *
     * @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 int
     */
    private int getIntegerValue(String s, String attribute, XMLStreamReader parser, boolean strict, int defaultValue)
        throws XMLStreamException {
        if (s != null) {
            try {
                return Integer.valueOf(s).intValue();
            } catch (NumberFormatException nfe) {
                if (strict) {
                    throw new XMLStreamException("Unable to parse element '" + attribute + "', must be an integer", parser.getLocation(), nfe);
                }
            }
        }
        return defaultValue;
    } //-- int getIntegerValue(String, String, XMLStreamReader, boolean, int)

    /**
     * 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)

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Edit the file at the reported location and write a plain decimal integer.
  2. For local-repository metadata, delete the whole artifact directory and let Maven re-resolve it.
  3. Pass strict=false to the reader if defaulting is acceptable.
  4. Check the writer/producer for locale-aware formatting (String.format without Locale.ROOT).

Example fix

<!-- before: ~/.m2/repository/.../maven-metadata.xml -->
<buildNumber>7a</buildNumber>
<!-- after -->
<buildNumber>7</buildNumber>

# or nuke the cache and re-resolve
rm -rf ~/.m2/repository/com/example/broken-artifact
Defensive patterns

Strategy: validation

Validate before calling

static boolean isPlainInt(String s) { return s != null && s.matches("[+-]?\\d+"); }

Try / catch

try {
    Metadata md = new MetadataStaxReader().read(file, true);
} catch (XMLStreamException e) {
    Files.deleteIfExists(file.toPath()); // derived file: purge, re-resolve next run
}

Prevention

When it happens

Trigger: Strict read of a model XML where an int field (e.g. <buildNumber>, retry counts, version-like numeric fields in maven-metadata.xml or toolchains.xml) is empty, contains '1.0', '12a', leading '+', or other non-integer text.

Common situations: Corrupted maven-metadata.xml in ~/.m2/repository after a failed download; files merged by version-control tools that garbled numeric fields; model versions where a field changed type; placeholder values never replaced in templates.

Understand the failure class

Related errors


AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21). Data as JSON: /api/errors/c9b995caf2e8936e. Report an issue: GitHub.