apache/flink · error · IllegalArgumentException
The record must not be null.
Error message
The record must not be null.
What it means
BooleanPrimitiveArraySerializer writes the array length then each element. serialize() rejects null explicitly because a null array has no length to emit and Flink's 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/BooleanPrimitiveArraySerializer.java:71
boolean[] copy = new boolean[from.length];
System.arraycopy(from, 0, copy, 0, from.length);
return copy;
}
@Override
public boolean[] copy(boolean[] from, boolean[] reuse) {
return copy(from);
}
@Override
public int getLength() {
return -1;
}
@Override
public void serialize(boolean[] 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.writeBoolean(record[i]);
}
}
@Override
public boolean[] deserialize(DataInputView source) throws IOException {
final int len = source.readInt();
boolean[] result = new boolean[len];
for (int i = 0; i < len; i++) {
result[i] = source.readBoolean();
}
View on GitHub (pinned to 2f3c205e92)
Solutions
- Initialize array fields to an empty array instead of null before they reach the sink/state.
- Filter or map out records with null arrays upstream so nulls never reach the serializer.
- If nullability is legitimate, switch the type to a nullable/object form (e.g., a Row with null handling or a custom nullable TypeInfo).
- Validate array fields are non-null before the serialization boundary in your mapper.
Example fix
// before: out.values may be null -> serializer.serialize(values) throws
// after: data.map(r -> { if (r.values == null) r.values = new boolean[0]; return r; }) Defensive patterns
Strategy: validation
Validate before calling
// Validate before serialize
if (record == null) {
throw new IllegalArgumentException("Refusing to serialize null boolean[]");
}
boolean[] safe = record == null ? new boolean[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 boolean[0];
serializer.serialize(record, target);
} else throw e;
} Prevention
- Default boolean[] fields to an empty array rather than null in POJO constructors.
- Filter or sanitize null arrays in a mapper before the sink/state boundary.
- If nullability is required, switch to a nullable type representation instead of a primitive array.
When it happens
Trigger: Calling serialize(null, target) on the boolean[] serializer — a record or field typed as boolean[] that resolved to null at runtime.
Common situations: A POJO/Row field typed boolean[] that is null due to upstream null input; a UDF returning null where a primitive array is expected; a nullable SQL column mapped to a primitive boolean[] type.
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/fca225eb92e7793f.
Report an issue: GitHub.