apache/flink · error · NumberFormatException
Empty field.
Error message
Empty field.
What it means
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.
Source
Thrown at flink-core/src/main/java/org/apache/flink/types/parser/ShortParser.java:128
/**
* Static utility to parse a field of type short from a byte sequence that represents text
* characters (such as when read from a file stream).
*
* @param bytes The bytes containing the text data that should be parsed.
* @param startPos The offset to start the parsing.
* @param length The length of the byte sequence (counting from the offset).
* @param delimiter The delimiter that terminates the field.
* @return The parsed value.
* @throws NumberFormatException Thrown when the value cannot be parsed because the text
* represents not a correct number.
*/
public static final short parseField(byte[] bytes, int startPos, int length, char delimiter) {
long val = 0;
boolean neg = false;
if (bytes[startPos] == delimiter) {
throw new NumberFormatException("Empty field.");
}
if (bytes[startPos] == '-') {
neg = true;
startPos++;
length--;
if (length == 0 || bytes[startPos] == delimiter) {
throw new NumberFormatException("Orphaned minus sign.");
}
}
for (; length > 0; startPos++, length--) {
if (bytes[startPos] == delimiter) {
return (short) (neg ? -val : val);
}
if (bytes[startPos] < 48 || bytes[startPos] > 57) {
throw new NumberFormatException("Invalid character.");
}View on GitHub (pinned to 2f3c205e92)
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
Example fix
// before
CREATE TABLE t (a SMALLINT, b SMALLINT, c SMALLINT) WITH ('format'='csv');
-- file row: 1,,3
// after
WITH ('format'='csv', 'csv.null-literal'='', 'csv.allow-null-literal'='true')
-- or write explicit null markers into the file: 1,\N,3 Defensive patterns
Strategy: validation
Validate before calling
for (String f : fields) {
if (f.isEmpty()) { /* substitute null per schema instead of parsing */ }
} Try / catch
catch (NumberFormatException e) { row.fieldReplacingNull(idx, null); } // with a String-typed reader in front Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Orphaned minus sign.
- Invalid character.
- Value overflow/underflow
- Invalid input: Empty string
- Empty field.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/7ad4a8a07efdf380.
Report an issue: GitHub.