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

getIntegerValue(s, attribute, parser, strict, defaultValue) converts an element's or attribute's value with Integer.valueOf. In strict mode a NumberFormatException is rethrown as this XMLStreamException with the original nfe attached as cause and the parser location; in lenient mode the defaultValue is returned. Integer.valueOf does not trim, so values like " 4", empty elements, and unresolved placeholders all fail.

Source

Thrown at src/mdo/reader-stax.vm:767

#if ( $hasIntegerField )
    /**
     * 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)

#end
    private static Map<String, String> doGetDefaultEntities() {
        return Map.ofEntries(
            entry("nbsp",   "\u00a0"), entry("iexcl",  "\u00a1"), entry("cent",   "\u00a2"), entry("pound",  "\u00a3"),
            entry("curren", "\u00a4"), entry("yen",    "\u00a5"), entry("brvbar", "\u00a6"), entry("sect",   "\u00a7"),
            entry("uml",    "\u00a8"), entry("copy",   "\u00a9"), entry("ordf",   "\u00aa"), entry("laquo",  "\u00ab"),
            entry("not",    "\u00ac"), entry("shy",    "\u00ad"), entry("reg",    "\u00ae"), entry("macr",   "\u00af"),
            entry("deg",    "\u00b0"), entry("plusmn", "\u00b1"), entry("sup2",   "\u00b2"), entry("sup3",   "\u00b3"),
            entry("acute",  "\u00b4"), entry("micro",  "\u00b5"), entry("para",   "\u00b6"), entry("middot", "\u00b7"),
            entry("cedil",  "\u00b8"), entry("sup1",   "\u00b9"), entry("ordm",   "\u00ba"), entry("raquo",  "\u00bb"),
            entry("frac14", "\u00bc"), entry("frac12", "\u00bd"), entry("frac34", "\u00be"), entry("iquest", "\u00bf"),
            entry("Agrave", "\u00c0"), entry("Aacute", "\u00c1"), entry("Acirc",  "\u00c2"), entry("Atilde", "\u00c3"),

View on GitHub (pinned to e4093d4e12)

Solutions

  1. Set the field to a plain decimal integer without whitespace, or remove the empty element so the default applies.
  2. Run ${...} interpolation before the document reaches this reader.
  3. If silently defaulting is acceptable, read with strict=false (defaultValue is returned).

Example fix

<!-- before -->
<forkCount>abc</forkCount>

<!-- after -->
<forkCount>2</forkCount>
Defensive patterns

Strategy: try-catch

Try / catch

try {
    Model model = reader.read(in, true);
} catch (XMLStreamException e) {
    if (e.getMessage() != null && e.getMessage().contains("must be an integer")) {
        NumberFormatException cause = (NumberFormatException) e.getCause(); // original parse failure
        // report field + location, ask the producer to fix the value
    }
    throw e;
}

Prevention

When it happens

Trigger: Strict read where an int-typed field holds non-numeric text: <forkCount>abc</forkCount>, an empty element, leading/trailing whitespace, or an uninterpolated ${threads} placeholder.

Common situations: Typos in numeric fields; empty elements where the author expected a default; property interpolation that never ran; locale-formatted numbers like 4,0.

Understand the failure class

Related errors


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