{"record":{"id":"6282bb6f41d4408b","repo":"apache/flink","slug":"invalid-character-6282bb","errorCode":null,"errorMessage":"Invalid character.","messagePattern":"Invalid character\\.","errorType":"exception","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/types/parser/ShortParser.java","lineNumber":145,"sourceCode":"        if (bytes[startPos] == delimiter) {\n            throw new NumberFormatException(\"Empty field.\");\n        }\n\n        if (bytes[startPos] == '-') {\n            neg = true;\n            startPos++;\n            length--;\n            if (length == 0 || bytes[startPos] == delimiter) {\n                throw new NumberFormatException(\"Orphaned minus sign.\");\n            }\n        }\n\n        for (; length > 0; startPos++, length--) {\n            if (bytes[startPos] == delimiter) {\n                return (short) (neg ? -val : val);\n            }\n            if (bytes[startPos] < 48 || bytes[startPos] > 57) {\n                throw new NumberFormatException(\"Invalid character.\");\n            }\n            val *= 10;\n            val += bytes[startPos] - 48;\n\n            if (val > OVERFLOW_BOUND && (!neg || val > UNDERFLOW_BOUND)) {\n                throw new NumberFormatException(\"Value overflow/underflow\");\n            }\n        }\n\n        return (short) (neg ? -val : val);\n    }\n}\n","sourceCodeStart":127,"sourceCodeEnd":158,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/types/parser/ShortParser.java#L127-L158","documentation":"ShortParser.parseField throws NumberFormatException(\"Invalid character.\") when a byte inside the numeric field is outside the ASCII digit range '0'..'57'. The parser is a strict byte-level parser: no signs mid-field, no spaces, no decimal points, no thousands separators, no scientific notation.","triggerScenarios":"A short-typed CSV field containing letters ('12a'), a plus sign ('+5' — only '-' is handled), whitespace (' 12' or '12 '), a decimal point ('3.5'), or a locale-style separator ('1,000' when ',' is not the delimiter).","commonSituations":"Excel-exported CSVs with thousands separators or trailing spaces; locales using different encodings; UTF-8 BOM bytes at the start of the first field; mismatched delimiter making text from the next column leak into a numeric column; plus-signed numbers produced by some exporters.","solutions":["Inspect the exact bytes of the failing field (hex dump the line) and clean the data: strip whitespace, remove separators, drop '+' signs, remove BOM","Verify the CSV delimiter and quote configuration so non-numeric columns are not merged into the short column","Pre-filter or map fields to sanitized strings before parsing to short","Switch the column type to STRING and cast/validate in application code if the data is inherently dirty"],"exampleFix":"// before\nRowCsvInputFormat fmt = new RowCsvInputFormat(path, Types.SHORT); // field: \" 12\"\n\n// after\n// sanitize first: read as STRING, trim, then parse\nString s = row.getFieldAs(0).trim();\nshort v = Short.parseShort(s.startsWith(\"+\") ? s.substring(1) : s);","handlingStrategy":"validation","validationCode":"static boolean isCleanShortToken(String s) {\n    return s != null && s.matches(\"-?[0-9]+\") && s.replace(\"-\", \"\").length() <= 5;\n}","typeGuard":null,"tryCatchPattern":"catch (NumberFormatException e) { /* quarantine row with offending token */ }","preventionTips":["Strip BOMs and trailing \\r when ingesting files","Reject '+', spaces, commas, and decimal points in numeric CSV tokens at the producer","Hex-dump the first failing line to see the exact offending byte"],"tags":["parsing","csv","short","invalid-input","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}