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

  1. Pass a non-null delimiter string (e.g., "," or "\t").
  2. If the delimiter is optional, default it before calling: String d = config != null ? config : ",".
  3. 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

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


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/a60edd21097ce2f1. Report an issue: GitHub.