{"record":{"id":"b24d639944a77c5f","repo":"apache/flink","slug":"line-could-not-be-parsed-parsererror-exp","errorCode":null,"errorMessage":"Line could not be parsed: '{}'\nParserError {} \nExpect field types: {} \nin file: {}","messagePattern":"Line could not be parsed: '(.+?)'\nParserError (.+?) \nExpect field types: (.+?) \nin file: (.+?)","errorType":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java","lineNumber":412,"sourceCode":"\n            if (fieldIncluded[field]) {\n                // parse field\n                @SuppressWarnings(\"unchecked\")\n                FieldParser<Object> parser = (FieldParser<Object>) this.fieldParsers[output];\n                Object reuse = holders[output];\n                startPos =\n                        parser.resetErrorStateAndParse(\n                                bytes, startPos, limit, this.fieldDelim, reuse);\n                holders[output] = parser.getLastResult();\n\n                // check parse result\n                if (startPos < 0) {\n                    // no good\n                    if (lenient) {\n                        return false;\n                    } else {\n                        String lineAsString = new String(bytes, offset, numBytes, getCharset());\n                        throw new ParseException(\n                                \"Line could not be parsed: '\"\n                                        + lineAsString\n                                        + \"'\\n\"\n                                        + \"ParserError \"\n                                        + parser.getErrorState()\n                                        + \" \\n\"\n                                        + \"Expect field types: \"\n                                        + fieldTypesToString()\n                                        + \" \\n\"\n                                        + \"in file: \"\n                                        + currentSplit.getPath());\n                    }\n                } else if (startPos == limit\n                        && field != fieldIncluded.length - 1\n                        && !FieldParser.endsWithDelimiter(bytes, startPos - 1, fieldDelim)) {\n                    // We are at the end of the record, but not all fields have been read\n                    // and the end is not a field delimiter indicating an empty last field.\n                    if (lenient) {","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java#L394-L430","documentation":"Thrown after a field parser returns a negative cursor (startPos < 0), indicating a parse failure with an error state such as NUMERIC_FORMAT_ERROR or EMPTY_FIELD. The message includes the offending line, the parser's ErrorState, the declared field types, and the source file path, so you can pinpoint which field/type/file combination failed. Like the other row checks, it only throws when lenient mode is off.","triggerScenarios":"A field value cannot be coerced to its declared type, e.g. 'abc' in an Integer column, an unparseable date string for java.sql.Date, a numeric overflow for the target primitive, or an empty value for a non-string type. ParserError in the message names the exact failure category.","commonSituations":"Header row left in the data file; locale-specific number formats ('1,5' vs '1.5'); date format mismatch between the file and Flink's expected SQL format; null/empty cells in a numeric column; schema drift after the producer added a column.","solutions":["Inspect the ParserError token in the message to identify the failure class (e.g. NUMERIC_FORMAT_ERROR, EMPTY_FIELD) and fix the offending value or type.","Pre-process the file to clean/normalize values (number separators, date formats, empty numeric cells).","Enable lenient mode (format.setLenient(true)) to skip unparseable rows if dropping them is acceptable.","Align the declared field types with the actual data; consider String + a parsing UDF for ambiguous columns."],"exampleFix":"// before: throws on header row 'name,age'\nformat.setFieldTypesGeneric(Integer.class, String.class);\n// after: skip header by reading first line as skip, or enable lenient\nformat.setSkipFirstLineAsHeader(true);\nformat.setLenient(true);","handlingStrategy":"validation","validationCode":"// Pre-validate a sample against the declared types before submitting\nObject[][] sample = readSample(path, 100);\nClass<?>[] types = declaredFieldTypes;\nfor (Object[] row : sample) {\n    for (int i = 0; i < row.length; i++) {\n        if (row[i] != null && !types[i].isInstance(coerce(row[i], types[i]))) {\n            throw new IllegalStateException(\"Column \" + i + \" value '\" + row[i]\n                + \"' not coercible to \" + types[i].getSimpleName());\n        }\n    }\n}","typeGuard":"// Narrow ambiguous columns to String and validate in a map\nDataStream<Row> safe = raw.map(r -> {\n    String v = (String) r.getField(idx);\n    try { return Integer.parseInt(v); }\n    catch (NumberFormatException e) { return null; /* or side-output */ }\n});","tryCatchPattern":"try {\n    return format.nextRecord(reuse);\n} catch (ParseException e) {\n    log.warn(\"Skipping unparseable row in {}: {}\", currentSplit, e.getMessage());\n    return null; // or enable lenient up front\n}","preventionTips":["Inspect the ParserError token in the message to classify the failure (numeric, empty, date).","Enable lenient mode if dropping malformed rows is acceptable; otherwise pre-clean the file.","Skip header rows with setSkipFirstLineAsHeader(true).","Normalize number/date formats in the source before reading."],"tags":["csv","input-format","data-quality","parsing"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}