apache/beam · error · RuntimeException
Null value found for field that doesn't support nulls.
Error message
Null value found for field that doesn't support nulls.
What it means
fieldValueToProto converts an in-memory Row field value into its proto representation. Beam requires that a non-nullable field always carry a value; if the value is null and fieldType.getNullable() is false, this RuntimeException is thrown rather than silently encoding a null into a field the schema says cannot be null.
Source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaTranslation.java:580
return builder.build();
}
public static Object rowFromProto(SchemaApi.Row row, FieldType fieldType) {
Row.Builder builder = Row.withSchema(fieldType.getRowSchema());
for (int i = 0; i < row.getValuesCount(); ++i) {
builder.addValue(
fieldValueFromProto(fieldType.getRowSchema().getField(i).getType(), row.getValues(i)));
}
return builder.build();
}
static SchemaApi.FieldValue fieldValueToProto(FieldType fieldType, Object value) {
FieldValue.Builder builder = FieldValue.newBuilder();
if (value == null) {
if (fieldType.getNullable()) {
return builder.build();
} else {
throw new RuntimeException("Null value found for field that doesn't support nulls.");
}
}
switch (fieldType.getTypeName()) {
case ARRAY:
return builder
.setArrayValue(
arrayValueToProto(fieldType.getCollectionElementType(), (Iterable) value))
.build();
case ITERABLE:
return builder
.setIterableValue(
iterableValueToProto(fieldType.getCollectionElementType(), (Iterable) value))
.build();
case MAP:
return builder
.setMapValue(
mapToProto(fieldType.getMapKeyType(), fieldType.getMapValueType(), (Map) value))View on GitHub (pinned to 12126d8942)
Solutions
- Fix the data: ensure every non-nullable field has a value before converting (validate or fill defaults).
- Mark the field nullable in the Schema (FieldType nullable(true)) if nulls are legitimate.
- Add a pre-conversion null check that substitutes defaults or fails fast with a clearer message.
- Trace which pipeline stage produced the invalid Row and add a DoFn-level validation there.
Example fix
// before FieldType fieldType = FieldType.STRING; // non-nullable, row value is null // after FieldType fieldType = FieldType.STRING.withNullable(true);
Defensive patterns
Strategy: validation
Validate before calling
for (Field f : schema.getFields()) { if (!f.getType().getNullable() && row.getValue(f.getName()) == null) throw new IllegalArgumentException("null in non-nullable field " + f.getName()); } Type guard
boolean isRowEncodable(Row row, Schema schema) { return schema.getFields().stream().allMatch(f -> f.getType().getNullable() || row.getValue(f.getName()) != null); } Try / catch
try { rowToProto(row); } catch (RuntimeException e) { if (e.getMessage().contains("Null value found")) { /* repair row or relax schema */ } else { throw e; } } Prevention
- Validate rows against schema nullability before serialization
- Use Row.withSchema field checks when building rows
- Keep schema nullability declarations in sync with actual data
- Treat DB NULL columns as nullable Beam fields
When it happens
Trigger: Calling rowToProto/fieldValueToProto (directly or via schema IO, e.g. ProtoSchema translation, schema-aware sinks) on a Row where a field declared non-nullable in the schema contains Java null.
Common situations: Row built with Row.withSchema missing values for some fields; mutation code that sets a field back to null; schema evolved to non-nullable after rows already contained nulls; mapping DB rows with NULL columns onto a non-nullable Beam schema.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- cannot encode a null Integer
- cannot encode a null Long
- cannot encode a null Short
- cannot encode a null BitSet
- cannot encode a null byte[]
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/e64317520509fd9a.
Report an issue: GitHub.