{"record":{"id":"b4b1bdd2cbc704c6","repo":"apache/flink","slug":"orphaned-minus-sign-b4b1bd","errorCode":null,"errorMessage":"Orphaned minus sign.","messagePattern":"Orphaned minus sign\\.","errorType":"exception","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/types/parser/LongParser.java","lineNumber":145,"sourceCode":"     * @param delimiter The delimiter that terminates the field.\n     * @return The parsed value.\n     * @throws NumberFormatException Thrown when the value cannot be parsed because the text\n     *     represents not a correct number.\n     */\n    public static final long parseField(byte[] bytes, int startPos, int length, char delimiter) {\n        long val = 0;\n        boolean neg = false;\n\n        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 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            // check for overflow / underflow\n            if (val < 0) {\n                // this is an overflow/underflow, unless we hit exactly the Long.MIN_VALUE\n                if (neg && val == Long.MIN_VALUE) {\n                    if (length == 1 || bytes[startPos + 1] == delimiter) {","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/types/parser/LongParser.java#L127-L163","documentation":"Thrown by LongParser.parseField when the field is a lone '-' with no digits. After consuming the sign and advancing the position, the parser sees length == 0 or the delimiter at the new position and rejects the sign-only field with NumberFormatException.","triggerScenarios":"Calling LongParser.parseField where the field slice between delimiters is exactly \"-\", e.g. \"100,-,200\" with ',' delimiter.","commonSituations":"Missing-value placeholders written as '-'; truncated negatives from partial writes; manual data edits dropping digits after the sign.","solutions":["Replace sign-only placeholders with real values or explicitly-handled empty fields.","Pre-check the slice for equality with \"-\" and route such records to error handling.","Screen incoming data for sign-only numeric fields."],"exampleFix":"// before\nlong v = LongParser.parseField(bytes, start, len, ',');\n\n// after\nString field = new String(bytes, start, len, StandardCharsets.UTF_8);\nif (field.equals(\"-\")) { throw new IllegalArgumentException(\"Sign-only long field at \" + start); }\nlong v = LongParser.parseField(bytes, start, len, ',');","handlingStrategy":"validation","validationCode":"if (len == 1 && bytes[start] == '-') {\n    throw new IllegalArgumentException(\"Sign-only long field\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    long v = LongParser.parseField(bytes, start, len, delim);\n} catch (NumberFormatException e) {\n    if (e.getMessage().equals(\"Orphaned minus sign.\")) { /* missing value policy */ }\n    else throw e;\n}","preventionTips":["Reject sign-only fields at ingestion.","Use a consistent missing-value representation in sources.","Screen numeric columns for malformed patterns."],"tags":["parser","long","malformed-number","csv","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}