apache/flink · error · IllegalArgumentException
The record must not be null.
Error message
The record must not be null.
What it means
IntPrimitiveArraySerializer writes the array length then each int. serialize() rejects null because a null array has no length to emit and primitive-array type information is non-nullable by contract.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/common/typeutils/base/array/IntPrimitiveArraySerializer.java:70
int[] copy = new int[from.length];
System.arraycopy(from, 0, copy, 0, from.length);
return copy;
}
@Override
public int[] copy(int[] from, int[] reuse) {
return copy(from);
}
@Override
public int getLength() {
return -1;
}
@Override
public void serialize(int[] 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++) {
target.writeInt(record[i]);
}
}
@Override
public int[] deserialize(DataInputView source) throws IOException {
final int len = source.readInt();
int[] result = new int[len];
for (int i = 0; i < len; i++) {
result[i] = source.readInt();
}
View on GitHub (pinned to 2f3c205e92)
Solutions
- Initialize int[] fields to an empty array instead of null before the sink/state.
- Filter out records with null arrays upstream.
- If nullability is legitimate, switch to an object/nullable type (e.g., Integer[] via ObjectArraySerializer or a Row with null handling).
- Add a null check in your mapper to default null arrays to empty.
Example fix
// before: out.ids may be null -> serializer.serialize(ids) throws
// after: data.map(r -> { if (r.ids == null) r.ids = new int[0]; return r; }) Defensive patterns
Strategy: validation
Validate before calling
// Validate before serialize int[] safe = record == null ? new int[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 int[0];
serializer.serialize(record, target);
} else throw e;
} Prevention
- Default int[] fields to an empty array rather than null in POJO constructors.
- Filter or sanitize null int arrays in a mapper before the sink/state boundary.
- If nullability is required, use a nullable type representation instead of a primitive array.
When it happens
Trigger: Calling serialize(null, target) on the int[] serializer — a field typed int[] that resolved to null at runtime.
Common situations: An int[] field that is null due to a null source value or uninitialized POJO; a UDF returning null where an int array is expected; a nullable SQL column mapped to a primitive int[].
Related errors
- The record must not be null.
- The record must not be null.
- The record must not be null.
- The record must not be null.
- The record must not be null.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/2d3edf9a79a9c0af.
Report an issue: GitHub.