{"record":{"id":"dbf50b3329acf088","repo":"apache/maven","slug":"unable-to-parse-element-must-be-an-integer","errorCode":null,"errorMessage":"Unable to parse element '{}', must be an integer","messagePattern":"Unable to parse element '(.+?)', must be an integer","errorType":"exception","errorClass":"XMLStreamException","httpStatus":null,"severity":"error","filePath":"src/mdo/reader-stax.vm","lineNumber":767,"sourceCode":"#if ( $hasIntegerField )\n    /**\n     * Method getIntegerValue.\n     *\n     * @param s a s object.\n     * @param strict a strict object.\n     * @param parser a parser object.\n     * @param attribute a attribute object.\n     * @throws XMLStreamException XMLStreamException if\n     * any.\n     * @return int\n     */\n    private int getIntegerValue(String s, String attribute, XMLStreamReader parser, boolean strict, int defaultValue) throws XMLStreamException {\n        if (s != null) {\n            try {\n                return Integer.valueOf(s).intValue();\n            } catch (NumberFormatException nfe) {\n                if (strict) {\n                    throw new XMLStreamException(\"Unable to parse element '\" + attribute + \"', must be an integer\", parser.getLocation(), nfe);\n                }\n            }\n        }\n        return defaultValue;\n    } //-- int getIntegerValue(String, String, XMLStreamReader, boolean)\n\n#end\n    private static Map<String, String> doGetDefaultEntities() {\n        return Map.ofEntries(\n            entry(\"nbsp\",   \"\\u00a0\"), entry(\"iexcl\",  \"\\u00a1\"), entry(\"cent\",   \"\\u00a2\"), entry(\"pound\",  \"\\u00a3\"),\n            entry(\"curren\", \"\\u00a4\"), entry(\"yen\",    \"\\u00a5\"), entry(\"brvbar\", \"\\u00a6\"), entry(\"sect\",   \"\\u00a7\"),\n            entry(\"uml\",    \"\\u00a8\"), entry(\"copy\",   \"\\u00a9\"), entry(\"ordf\",   \"\\u00aa\"), entry(\"laquo\",  \"\\u00ab\"),\n            entry(\"not\",    \"\\u00ac\"), entry(\"shy\",    \"\\u00ad\"), entry(\"reg\",    \"\\u00ae\"), entry(\"macr\",   \"\\u00af\"),\n            entry(\"deg\",    \"\\u00b0\"), entry(\"plusmn\", \"\\u00b1\"), entry(\"sup2\",   \"\\u00b2\"), entry(\"sup3\",   \"\\u00b3\"),\n            entry(\"acute\",  \"\\u00b4\"), entry(\"micro\",  \"\\u00b5\"), entry(\"para\",   \"\\u00b6\"), entry(\"middot\", \"\\u00b7\"),\n            entry(\"cedil\",  \"\\u00b8\"), entry(\"sup1\",   \"\\u00b9\"), entry(\"ordm\",   \"\\u00ba\"), entry(\"raquo\",  \"\\u00bb\"),\n            entry(\"frac14\", \"\\u00bc\"), entry(\"frac12\", \"\\u00bd\"), entry(\"frac34\", \"\\u00be\"), entry(\"iquest\", \"\\u00bf\"),\n            entry(\"Agrave\", \"\\u00c0\"), entry(\"Aacute\", \"\\u00c1\"), entry(\"Acirc\",  \"\\u00c2\"), entry(\"Atilde\", \"\\u00c3\"),","sourceCodeStart":749,"sourceCodeEnd":785,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/src/mdo/reader-stax.vm#L749-L785","documentation":"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.","triggerScenarios":"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.","commonSituations":"Typos in numeric fields; empty elements where the author expected a default; property interpolation that never ran; locale-formatted numbers like 4,0.","solutions":["Set the field to a plain decimal integer without whitespace, or remove the empty element so the default applies.","Run ${...} interpolation before the document reaches this reader.","If silently defaulting is acceptable, read with strict=false (defaultValue is returned)."],"exampleFix":"<!-- before -->\n<forkCount>abc</forkCount>\n\n<!-- after -->\n<forkCount>2</forkCount>","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    Model model = reader.read(in, true);\n} catch (XMLStreamException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"must be an integer\")) {\n        NumberFormatException cause = (NumberFormatException) e.getCause(); // original parse failure\n        // report field + location, ask the producer to fix the value\n    }\n    throw e;\n}","preventionTips":["Lint numeric fields in authoring tools.","Interpolate placeholders before parsing.","Prefer omitting the element over leaving it empty when a default exists."],"tags":["xml","stax","type-conversion","number-format","parsing"],"backgroundTag":"xml-number-format-exception","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}