{"record":{"id":"3d3612aefe743133","repo":"apache/flink","slug":"there-is-leading-or-trailing-whitespace-in-the-num-3d3612","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/DoubleParser.java","lineNumber":101,"sourceCode":"    /**\n     * Static utility to parse a field of type double 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 double parseField(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 Double.parseDouble(str);\n    }\n}\n","sourceCodeStart":83,"sourceCodeEnd":109,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/types/parser/DoubleParser.java#L83-L109","documentation":"Thrown by DoubleParser.parseField when a double text field has leading or trailing whitespace. The parser measures the field up to the delimiter with nextStringLength, checks the first and last bytes with Character.isWhitespace, and rejects before handing the string to Double.parseDouble (which would not accept the padding either).","triggerScenarios":"Calling DoubleParser.parseField(bytes, startPos, length, delimiter) on fields like \" 1.5\" or \"2.5e3 \" — padding inside the delimited column.","commonSituations":"Spreadsheet/CSV exports with padded columns; trailing \\r from CRLF line endings on the last field; fixed-width extracts sliced with leading spaces included.","solutions":["Trim the field before parsing, or clean the input so numeric columns carry no padding.","Normalize line endings (\\r\\n -> \\n) for files sourced from Windows systems.","Add fixture-based tests using real exported files to catch formatting drift."],"exampleFix":"// before\ndouble v = DoubleParser.parseField(bytes, start, len, '|');\n\n// after\nString field = new String(bytes, start, len, StandardCharsets.UTF_8).trim();\ndouble v = Double.parseDouble(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 double field\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    double v = DoubleParser.parseField(bytes, start, len, delim);\n} catch (NumberFormatException e) {\n    double v = Double.parseDouble(new String(bytes, start, len, StandardCharsets.UTF_8).trim());\n}","preventionTips":["Trim numeric fields before parsing.","Normalize line endings for cross-platform files.","Use realistic fixtures in CI to detect padding introduced by exporters."],"tags":["parser","double","whitespace","csv","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}