{"record":{"id":"7ad4a8a07efdf380","repo":"apache/flink","slug":"empty-field-7ad4a8","errorCode":null,"errorMessage":"Empty field.","messagePattern":"Empty field\\.","errorType":"exception","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/types/parser/ShortParser.java","lineNumber":128,"sourceCode":"\n    /**\n     * Static utility to parse a field of type short 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 NumberFormatException Thrown when the value cannot be parsed because the text\n     *     represents not a correct number.\n     */\n    public static final short 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 (short) (neg ? -val : val);\n            }\n            if (bytes[startPos] < 48 || bytes[startPos] > 57) {\n                throw new NumberFormatException(\"Invalid character.\");\n            }","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/types/parser/ShortParser.java#L110-L146","documentation":"ShortParser.parseField throws NumberFormatException(\"Empty field.\") when the very first byte of the field equals the configured delimiter, i.e. the field contains no characters at all before the delimiter. The parser cannot produce a short from an empty string.","triggerScenarios":"Reading a CSV row where a SMALLINT/SHORT column is empty between two delimiters (e.g. '1,,3'), or where a row has fewer columns than the schema and adjacent delimiters line up, or a trailing empty last field when the line ends with the delimiter.","commonSituations":"Null or missing values represented as empty strings instead of a literal like '\\N' or 'null'; rows with ragged column counts; line endings containing the delimiter (e.g. reading '\\r'-terminated files with ',' handling quirks); schema declaring more fields than the file provides.","solutions":["Configure the CSV format to allow null values for the field (table.exec or connector csv options such as null-literal / handling of empty strings) so empties become NULL instead of being parsed","Fix the data so empty numeric fields carry an explicit null literal (e.g. '\\N' or configured null string)","Align the declared schema's field count and order with the actual file","Filter or clean malformed rows upstream before the parse"],"exampleFix":"// before\nCREATE TABLE t (a SMALLINT, b SMALLINT, c SMALLINT) WITH ('format'='csv');\n-- file row: 1,,3\n\n// after\nWITH ('format'='csv', 'csv.null-literal'='', 'csv.allow-null-literal'='true')\n-- or write explicit null markers into the file: 1,\\N,3","handlingStrategy":"validation","validationCode":"for (String f : fields) {\n    if (f.isEmpty()) { /* substitute null per schema instead of parsing */ }\n}","typeGuard":null,"tryCatchPattern":"catch (NumberFormatException e) { row.fieldReplacingNull(idx, null); } // with a String-typed reader in front","preventionTips":["Configure csv null-literal for empty numeric fields","Never leave numeric columns empty in exports; use an explicit null token","Fuzz-test parsers with empty, '-', and boundary values"],"tags":["parsing","csv","short","empty-field","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}