apache/beam · error · java.lang.RuntimeException
Null value set on non-nullable field <field>
Error message
Null value set on non-nullable field <field>
What it means
RowWithGetters.getValue checks that a field accessed through its getters is not null when the schema declares the field non-nullable. A null was stored (via a getter) in a field declared non-nullable, so reading it throws RuntimeException. This is a data-integrity check for the row's declared schema.
Source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/values/RowWithGetters.java:93
cache = new TreeMap<>();
}
fieldValue =
cache.computeIfAbsent(
fieldIdx,
new Function<Integer, @Nullable Object>() {
@Override
public @Nullable Object apply(Integer idx) {
FieldValueGetter<T, Object> getter = getters.get(idx);
checkStateNotNull(getter);
return getter.get(getterTarget);
}
});
} else {
fieldValue = getters.get(fieldIdx).get(getterTarget);
}
if (fieldValue == null && !field.getType().getNullable()) {
throw new RuntimeException("Null value set on non-nullable field " + field);
}
return (W) fieldValue;
}
public TypeDescriptor<?> getGetterTargetType() {
return getterTargetType;
}
private boolean cacheFieldType(Field field) {
TypeName typeName = field.getType().getTypeName();
return typeName.equals(TypeName.MAP)
|| typeName.equals(TypeName.ARRAY)
|| typeName.equals(TypeName.ITERABLE);
}
@Override
public int getFieldCount() {
return getters.size();View on GitHub (pinned to 12126d8942)
Solutions
- Make the field nullable in the schema (FieldType.withNullable(true)) or in the POJO annotation
- Ensure the backing object's field is populated before wrapping it in a Row (set defaults in the constructor)
- Rebuild/validate the row after mutations; use Schema validation on creation instead of trusting lazy getters
Example fix
// before
class User { String id; } // id left null, schema non-nullable
// after
class User { String id = "unknown"; } // or mark field nullable in schema Defensive patterns
Strategy: try-catch
Validate before calling
schema.getFields().forEach(f -> { if (!f.getType().getNullable() && backing.get(f.getName()) == null) throw new IllegalStateException("null in non-nullable field " + f.getName()); }); Type guard
boolean isReadable(Row row, int idx) { return idx >= 0 && idx < row.getSchema().getFieldCount(); } Try / catch
try { W v = row.getValue(idx); } catch (RuntimeException e) { if (e.getMessage().startsWith("Null value set on non-nullable field")) { /* handle null per schema */ } else throw e; } Prevention
- Initialize all non-nullable POJO fields with defaults
- Avoid mutating backing objects after wrapping in a Row
- Align @DefaultSchema annotations with runtime nullability
When it happens
Trigger: Calling row.getValue(idx)/accessors on a RowWithGetters whose underlying getter target object has null in a field whose Schema.FieldType.getNullable() is false; typically the row was built without validation or the backing object mutated after creation.
Common situations: POJOs annotated with @DefaultSchema where fields are null but the generated schema marks them non-nullable; mutation of the backing object after row creation; schema/POJO divergence after refactoring.
Related errors
- Cannot provide a coder for a Beam Row. Please provide a sche
- Row expected <fieldCount> fields (<fields>). initialized wit
- Not a primitive type for field name %s: %s
- %s is not nullable in field %s
- %s is not nullable in Array field %s
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/9544ce9f9f222e19.
Report an issue: GitHub.