apache/flink · error · IllegalArgumentException

The record must not be null.

Error message

The record must not be null.

What it means

StringArraySerializer writes the array length then each string via StringValue.writeString. serialize() rejects a null array (not null elements) because a null array has no length to emit; individual element strings may be null but the array container itself may not.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/common/typeutils/base/array/StringArraySerializer.java:71

        String[] target = new String[from.length];
        System.arraycopy(from, 0, target, 0, from.length);
        return target;
    }

    @Override
    public String[] copy(String[] from, String[] reuse) {
        return copy(from);
    }

    @Override
    public int getLength() {
        return -1;
    }

    @Override
    public void serialize(String[] record, DataOutputView target) throws IOException {
        if (record == null) {
            throw new IllegalArgumentException("The record must not be null.");
        }

        final int len = record.length;
        target.writeInt(len);
        for (int i = 0; i < len; i++) {
            StringValue.writeString(record[i], target);
        }
    }

    @Override
    public String[] deserialize(DataInputView source) throws IOException {
        final int len = source.readInt();
        String[] array = new String[len];

        for (int i = 0; i < len; i++) {
            array[i] = StringValue.readString(source);
        }

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Initialize String[] fields to an empty array instead of null before the sink/state.
  2. Filter out records with null string arrays upstream.
  3. If nullability is legitimate, switch to a nullable representation (e.g., a Row/List with null handling).
  4. Add a null check in your mapper to default null arrays to empty.

Example fix

// before: out.tags may be null -> serializer.serialize(tags) throws
// after: data.map(r -> { if (r.tags == null) r.tags = new String[0]; return r; })
Defensive patterns

Strategy: validation

Validate before calling

// Validate before serialize (the array container, not individual elements)
String[] safe = record == null ? new String[0] : record;
serializer.serialize(safe, target);

Try / catch

try {
    serializer.serialize(record, target);
} catch (IllegalArgumentException e) {
    if (e.getMessage().equals("The record must not be null.")) {
        record = new String[0];
        serializer.serialize(record, target);
    } else throw e;
}

Prevention

When it happens

Trigger: Calling serialize(null, target) on the String[] serializer — a String[] field that resolved to null at runtime.

Common situations: A String[] field that is null due to a null source value; a UDF returning null where a string array is expected; a nullable SQL ARRAY<STRING> column mapped to a String[] that came back null.

Related errors


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