{"record":{"id":"e7833a7e8997c33d","repo":"apache/flink","slug":"value-overflow","errorCode":null,"errorMessage":"value overflow","messagePattern":"value overflow","errorType":"exception","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/types/parser/LongParser.java","lineNumber":166,"sourceCode":"\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) {\n                        return Long.MIN_VALUE;\n                    } else {\n                        throw new NumberFormatException(\"value overflow\");\n                    }\n                } else {\n                    throw new NumberFormatException(\"value overflow\");\n                }\n            }\n        }\n        return neg ? -val : val;\n    }\n}\n","sourceCodeStart":148,"sourceCodeEnd":176,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/types/parser/LongParser.java#L148-L176","documentation":"Thrown by LongParser.parseField when the parsed digit sequence overflows or underflows the 64-bit signed long range. The parser accumulates the value manually (val = val*10 + digit) and detects wrap-around only after val has already gone negative, so this fires when the accumulated value crossed Long.MAX_VALUE (or went below Long.MIN_VALUE for a negative number with extra digits).","triggerScenarios":"Reading a text/CSV field with a RowCsvInputFormat or table source backed by these parsers where the numeric field exceeds 9223372036854775807 (e.g. '99999999999999999999'), or a negative field smaller than -9223372036854775808. Specifically this is the inner throw for the case neg && val == Long.MIN_VALUE but more digits or a non-delimiter byte follow the exact MIN_VALUE digit sequence.","commonSituations":"IDs (order ids, snowflake ids, timestamps in nanos) serialized as text and read into a LONG column; upstream producers switched from int to wider numeric ids; delimiter misconfiguration making the parser consume several fields as one long number; leading plus sign or scientific notation which the parser rejects as overflow/invalid.","solutions":["Verify the field's true magnitude; if it can exceed 2^63-1, change the sink/target type to STRING or DECIMAL instead of LONG","Check the delimiter configuration of the CSV reader (flink.connector.csv delimiter / field delimiter) so a single numeric field is not concatenated from multiple columns","Sanitize or reject offending rows upstream (filter/validate the string length and digit-only content before parsing)","If the value is actually within range, check for stray characters (e.g. a trailing digit after the Long.MIN_VALUE literal) that make an exact MIN_VALUE parse look like overflow"],"exampleFix":"// before\nCsvReader csv = env.readFile(new RowCsvInputFormat(path, Types.LONG), path);\n\n// after: widen the target type for oversized ids\nRowCsvInputFormat fmt = new RowCsvInputFormat(path, Types.STRING, new boolean[]{true});\n// then parse defensively:\nlong v;\ntry { v = Long.parseLong(s.trim()); } catch (NumberFormatException e) { v = /* handle */ 0L; }","handlingStrategy":"validation","validationCode":"boolean fitsLong(String s) {\n    String t = s.trim();\n    if (t.isEmpty() || !t.matches(\"-?\\\\d+\")) return false;\n    String digits = t.startsWith(\"-\") ? t.substring(1) : t;\n    if (digits.length() > 19) return false;\n    try { Long.parseLong(t); return true; }\n    catch (NumberFormatException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"catch (NumberFormatException e) { log.warn(\"long overflow in field, routing to DLQ: {}\", field); emitToDeadLetterQueue(row); }","preventionTips":["Declare BIGINT columns only for values verified to fit in 2^63-1","Pre-scan file column max length; >19 digits means switch to STRING/DECIMAL","Never let ids that may grow (snowflake, nanosecond timestamps) be typed LONG in text formats"],"tags":["parsing","csv","long","overflow","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}