{"record":{"id":"53eedaa7daefc952","repo":"apache/maven","slug":"unable-to-parse-element-must-be-a-byte","errorCode":null,"errorMessage":"Unable to parse element '{}', must be a byte","messagePattern":"Unable to parse element '(.+?)', must be a byte","errorType":"exception","errorClass":"XMLStreamException","httpStatus":null,"severity":"error","filePath":"src/mdo/reader.vm","lineNumber":792,"sourceCode":"    /**\n     * Method getByteValue.\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 byte\n     */\n    private byte getByteValue(String s, String attribute, XMLStreamReader parser, boolean strict)\n        throws XMLStreamException {\n        if (s != null) {\n            try {\n                return Byte.valueOf(s).byteValue();\n            } catch (NumberFormatException nfe) {\n                if (strict) {\n                    throw new XMLStreamException(\"Unable to parse element '\" + attribute + \"', must be a byte\", parser.getLocation(), nfe);\n                }\n            }\n        }\n        return 0;\n    } //-- byte getByteValue(String, String, XMLStreamReader, boolean)\n\n    /**\n     * Method getCharacterValue.\n     *\n     * @param s a s object.\n     * @param parser a parser object.\n     * @param attribute a attribute object.\n     * @throws XMLStreamException XMLStreamException if\n     * any.\n     * @return char\n     */\n    private char getCharacterValue(String s, String attribute, XMLStreamReader parser)\n        throws XMLStreamException {","sourceCodeStart":774,"sourceCodeEnd":810,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/src/mdo/reader.vm#L774-L810","documentation":"This message is thrown by the StAX model reader generated from src/mdo/reader.vm (the Modello template behind readers like MetadataStaxReader and MavenStaxReader) when a model XML field typed as byte contains text that Byte.valueOf(String) cannot parse. In strict parsing mode (the default for most generated readers) the helper getByteValue rethrows the NumberFormatException as a javax.xml.stream.XMLStreamException, aborting the whole document parse. In non-strict mode the error is swallowed and the field silently defaults to 0.","triggerScenarios":"Calling a generated reader such as new MetadataStaxReader().read(inputStream, strict=true) or MavenStaxReader.read(...) on XML where a byte-typed element/attribute holds 'abc', an empty string, a decimal like '1.5', or a value outside -128..127. Only reachable for models that actually declare a byte field; the read fails on the first malformed value.","commonSituations":"Hand-edited maven-metadata.xml or other model files with typos in numeric fields; files written by a buggy custom plugin; byte field overflow (e.g. '255') from tools that do not clamp byte ranges; CI caches poisoned with a truncated download.","solutions":["Open the file named in the exception location, find the offending element, and put a valid byte (-128 to 127) in it.","If the file is derived (maven-metadata-*.xml, plugin metadata), delete the local copy and let Maven re-download it instead of hand-fixing it.","If you control the caller and can tolerate defaults, invoke the reader with strict=false so malformed values fall back to 0 instead of aborting.","Regenerate/repair the producer that wrote the bad value so the error does not recur on next write."],"exampleFix":"<!-- before: mdo model XML -->\n<myByteField>300</myByteField>\n<!-- after -->\n<myByteField>127</myByteField>\n\n// before\nMetadata md = new MetadataStaxReader().read(file, true); // XMLStreamException\n\n// after\ntry {\n    Metadata md = new MetadataStaxReader().read(file, true);\n} catch (XMLStreamException e) {\n    Files.deleteIfExists(file.toPath()); // force re-download of derived metadata\n}","handlingStrategy":"try-catch","validationCode":"byte checkByte(String s) { return Byte.parseByte(s.trim()); } // run on the raw text before handing the XML to the reader","typeGuard":null,"tryCatchPattern":"try {\n    Model m = new GeneratedStaxReader().read(file, true);\n} catch (XMLStreamException e) {\n    // message names the offending attribute; location gives line/column\n    log.warn(\"model parse failed at \" + e.getLocation().getLineNumber(), e);\n}","preventionTips":["Never hand-edit generated model XML; regenerate from the source of truth.","Run strict parsing in CI on every committed XML so bad values fail the build early.","Keep producers formatting numbers with Locale.ROOT."],"tags":["xml","stax","modello","number-format","strict-parsing"],"backgroundTag":"xml-numeric-field-parse-failed","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}