{"record":{"id":"c4d7a20bba417d2a","repo":"apache/flink","slug":"there-is-leading-or-trailing-whitespace-in-the-num-c4d7a2","errorCode":null,"errorMessage":"There is leading or trailing whitespace in the numeric field.","messagePattern":"There is leading or trailing whitespace in the numeric field\\.","errorType":"exception","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/types/parser/BigIntParser.java","lineNumber":104,"sourceCode":"     * Static utility to parse a field of type BigInteger from a byte sequence that represents text\n     * characters (such as when read from a file stream).\n     *\n     * @param bytes The bytes containing the text data that should be parsed.\n     * @param startPos The offset to start the parsing.\n     * @param length The length of the byte sequence (counting from the offset).\n     * @param delimiter The delimiter that terminates the field.\n     * @return The parsed value.\n     * @throws IllegalArgumentException Thrown when the value cannot be parsed because the text\n     *     represents not a correct number.\n     */\n    public static final BigInteger parseField(\n            byte[] bytes, int startPos, int length, char delimiter) {\n        final int limitedLen = nextStringLength(bytes, startPos, length, delimiter);\n\n        if (limitedLen > 0\n                && (Character.isWhitespace(bytes[startPos])\n                        || Character.isWhitespace(bytes[startPos + limitedLen - 1]))) {\n            throw new NumberFormatException(\n                    \"There is leading or trailing whitespace in the numeric field.\");\n        }\n\n        final String str = new String(bytes, startPos, limitedLen, ConfigConstants.DEFAULT_CHARSET);\n        return new BigInteger(str);\n    }\n}\n","sourceCodeStart":86,"sourceCodeEnd":112,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/types/parser/BigIntParser.java#L86-L112","documentation":"Thrown by BigIntParser.parseField when a BigInteger text field starts or ends with whitespace. The parser computes the field length up to the delimiter via nextStringLength, then checks the first and last byte with Character.isWhitespace and rejects before delegating to new BigInteger(str), which would fail anyway.","triggerScenarios":"Calling BigIntParser.parseField(bytes, startPos, length, delimiter) where bytes[startPos] or the byte just before the delimiter is a space, tab, or \\r — e.g. the field \" 42\" or \"42 \".","commonSituations":"Padded numeric columns from spreadsheet/CSV exports; trailing \\r from CRLF line endings on the last field of a row; hand-built test fixtures with stray spaces.","solutions":["Trim whitespace from the field bytes before calling parseField.","Normalize CRLF input and re-export sources without column padding.","Validate raw rows in an integration test with representative files to catch formatting drift early."],"exampleFix":"// before\nBigInteger v = BigIntParser.parseField(bytes, start, len, ',');\n\n// after\nString field = new String(bytes, start, len, StandardCharsets.UTF_8).trim();\nBigInteger v = new BigInteger(field);","handlingStrategy":"validation","validationCode":"int end = start + len;\nif (len > 0 && (Character.isWhitespace(bytes[start]) || Character.isWhitespace(bytes[end - 1]))) {\n    throw new IllegalArgumentException(\"Untrimmed BigInteger field\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    BigInteger v = BigIntParser.parseField(bytes, start, len, delim);\n} catch (NumberFormatException e) {\n    // re-parse trimmed or divert to error side output\n}","preventionTips":["Trim field bytes before numeric parsing.","Strip \\r when processing CRLF files.","Screen numeric columns for whitespace padding in data-quality checks."],"tags":["parser","bigint","whitespace","csv","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}