apache/flink · error · IllegalArgumentException
Delimiter must not be null
Error message
Delimiter must not be null
What it means
Thrown by GenericCsvInputFormat.setFieldDelimiter(String) when the delimiter argument is null. The delimiter is converted to bytes using the configured charset; a null value cannot be encoded and the field parser relies on a non-null byte delimiter to tokenize records, so it is rejected eagerly.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java:149
return commentPrefix;
}
public void setCommentPrefix(String commentPrefix) {
if (commentPrefix != null) {
this.commentPrefix = commentPrefix.getBytes(getCharset());
} else {
this.commentPrefix = null;
}
this.commentPrefixString = commentPrefix;
}
public byte[] getFieldDelimiter() {
return fieldDelim;
}
public void setFieldDelimiter(String delimiter) {
if (delimiter == null) {
throw new IllegalArgumentException("Delimiter must not be null");
}
this.fieldDelim = delimiter.getBytes(getCharset());
this.fieldDelimString = delimiter;
}
public boolean isLenient() {
return lenient;
}
public void setLenient(boolean lenient) {
this.lenient = lenient;
}
public boolean isSkippingFirstLineAsHeader() {
return skipFirstLineAsHeader;
}
View on GitHub (pinned to 2f3c205e92)
Solutions
- Pass a non-null delimiter string (e.g., "," or "\t").
- If the delimiter is optional, default it before calling: String d = config != null ? config : ",".
- Use the constructor / builder variant that accepts a delimiter directly to avoid forgetting the call.
Example fix
// before
csvFormat.setFieldDelimiter(delimiter); // delimiter is null
// after
String delimiter = Optional.ofNullable(cfgDelimiter).orElse(",");
csvFormat.setFieldDelimiter(delimiter); Defensive patterns
Strategy: validation
Validate before calling
String delim = Optional.ofNullable(configDelimiter).orElse(",");
Objects.requireNonNull(delim, "CSV delimiter must not be null");
csvFormat.setFieldDelimiter(delim); Type guard
static boolean isValidDelimiter(String d) {
return d != null && !d.isEmpty();
} Prevention
- Default optional delimiters to "," before calling setFieldDelimiter.
- Treat delimiter as a required config field in schema builders.
- Unit test the CSV builder with a missing delimiter to confirm it defaults rather than throws.
When it happens
Trigger: Calling setFieldDelimiter(null); passing a delimiter variable that was never initialized; a config-driven delimiter that resolved to null.
Common situations: Building a CSV reader where the delimiter comes from an optional config that wasn't supplied; refactoring that drops the assignment; tests that pass null to probe defaults.
Related errors
- Field types must not be null.
- Type for included field {} should not be null.
- Output file path may not be null.
- The type '{}' is not supported for the CSV input format.
- Field indices must not be smaller than zero.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/a60edd21097ce2f1.
Report an issue: GitHub.