apache/flink · error · IllegalArgumentException

Delimiter must not be null

Error message

Delimiter must not be null

What it means

DelimitedInputFormat splits input into records by scanning for a delimiter byte sequence; a null delimiter has no meaning and would break every record boundary. setDelimiter(byte[]) rejects null with IllegalArgumentException. The format also clears the cached string form so the two stay consistent.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/common/io/DelimitedInputFormat.java:231

     * @param charset name of the charset
     */
    @PublicEvolving
    public void setCharset(String charset) {
        this.charsetName = Preconditions.checkNotNull(charset);
        this.charset = null;

        if (this.delimiterString != null) {
            this.delimiter = delimiterString.getBytes(getCharset());
        }
    }

    public byte[] getDelimiter() {
        return delimiter;
    }

    public void setDelimiter(byte[] delimiter) {
        if (delimiter == null) {
            throw new IllegalArgumentException("Delimiter must not be null");
        }
        this.delimiter = delimiter;
        this.delimiterString = null;
    }

    public void setDelimiter(char delimiter) {
        setDelimiter(String.valueOf(delimiter));
    }

    public void setDelimiter(String delimiter) {
        if (delimiter == null) {
            throw new IllegalArgumentException("Delimiter must not be null");
        }
        this.delimiter = delimiter.getBytes(getCharset());
        this.delimiterString = delimiter;
    }

    public int getLineLengthLimit() {

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Provide a non-null byte[] delimiter, e.g. format.setDelimiter("\n".getBytes(StandardCharsets.UTF_8)).
  2. Default the delimiter to newline when the configured value is null before calling setDelimiter.
  3. Prefer the String overload setDelimiter(String) or the char overload setDelimiter(char) for readability.

Example fix

// before
byte[] delim = config.get("delimiter"); // null
format.setDelimiter(delim); // throws

// after
byte[] delim = config.get("delimiter");
format.setDelimiter(delim != null ? delim : "\n".getBytes(StandardCharsets.UTF_8));
Defensive patterns

Strategy: validation

Validate before calling

byte[] delim = configuredDelimiter;
if (delim == null) {
    delim = "\n".getBytes(StandardCharsets.UTF_8);
}
format.setDelimiter(delim);

Prevention

When it happens

Trigger: Calling format.setDelimiter((byte[]) null). Common when the delimiter comes from a config/parameter that was not set and resolved to null.

Common situations: Reading a CSV/TSV/text input where the separator property is missing from configuration; passing a byte[] that was never initialized; chaining getBytes on a null String before calling setDelimiter.

Related errors


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