{"record":{"id":"8dbfb17614ef8880","repo":"apache/flink","slug":"there-is-leading-or-trailing-whitespace-in-the-num-8dbfb1","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/FloatParser.java","lineNumber":98,"sourceCode":"    /**\n     * Static utility to parse a field of type float 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 float 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 Float.parseFloat(str);\n    }\n}\n","sourceCodeStart":80,"sourceCodeEnd":106,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/types/parser/FloatParser.java#L80-L106","documentation":"Thrown by FloatParser.parseField when a float text field has leading or trailing whitespace. After limiting the field to the delimiter via nextStringLength, the parser checks the boundary bytes with Character.isWhitespace and rejects before calling Float.parseFloat.","triggerScenarios":"Calling FloatParser.parseField(bytes, startPos, length, delimiter) with fields like \" 0.5f\" or \"1.5 \" — padding or a trailing \\r inside the column.","commonSituations":"Padded columns from CSV/spreadsheet exports; CRLF line endings leaving \\r on the last field; test fixtures built with string concatenation adding stray spaces.","solutions":["Trim the field bytes before parsing.","Normalize CRLF input and configure delimiters so padding stays outside numeric columns.","Validate representative input files in CI to catch format drift."],"exampleFix":"// before\nfloat v = FloatParser.parseField(bytes, start, len, '|');\n\n// after\nString field = new String(bytes, start, len, StandardCharsets.UTF_8).trim();\nfloat v = Float.parseFloat(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 float field\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    float v = FloatParser.parseField(bytes, start, len, delim);\n} catch (NumberFormatException e) {\n    float v = Float.parseFloat(new String(bytes, start, len, StandardCharsets.UTF_8).trim());\n}","preventionTips":["Trim float columns at ingestion.","Handle CRLF trailing \\r on last fields.","Add fixture-based tests for exporter output."],"tags":["parser","float","whitespace","csv","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}