{"record":{"id":"9544ce9f9f222e19","repo":"apache/beam","slug":"null-value-set-on-non-nullable-field-field","errorCode":null,"errorMessage":"Null value set on non-nullable field <field>","messagePattern":"Null value set on non-nullable field <field>","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/values/RowWithGetters.java","lineNumber":93,"sourceCode":"        cache = new TreeMap<>();\n      }\n      fieldValue =\n          cache.computeIfAbsent(\n              fieldIdx,\n              new Function<Integer, @Nullable Object>() {\n                @Override\n                public @Nullable Object apply(Integer idx) {\n                  FieldValueGetter<T, Object> getter = getters.get(idx);\n                  checkStateNotNull(getter);\n                  return getter.get(getterTarget);\n                }\n              });\n    } else {\n      fieldValue = getters.get(fieldIdx).get(getterTarget);\n    }\n\n    if (fieldValue == null && !field.getType().getNullable()) {\n      throw new RuntimeException(\"Null value set on non-nullable field \" + field);\n    }\n    return (W) fieldValue;\n  }\n\n  public TypeDescriptor<?> getGetterTargetType() {\n    return getterTargetType;\n  }\n\n  private boolean cacheFieldType(Field field) {\n    TypeName typeName = field.getType().getTypeName();\n    return typeName.equals(TypeName.MAP)\n        || typeName.equals(TypeName.ARRAY)\n        || typeName.equals(TypeName.ITERABLE);\n  }\n\n  @Override\n  public int getFieldCount() {\n    return getters.size();","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/values/RowWithGetters.java#L75-L111","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nclass User { String id; } // id left null, schema non-nullable\n// after\nclass User { String id = \"unknown\"; } // or mark field nullable in schema","handlingStrategy":"try-catch","validationCode":"schema.getFields().forEach(f -> { if (!f.getType().getNullable() && backing.get(f.getName()) == null) throw new IllegalStateException(\"null in non-nullable field \" + f.getName()); });","typeGuard":"boolean isReadable(Row row, int idx) { return idx >= 0 && idx < row.getSchema().getFieldCount(); }","tryCatchPattern":"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; }","preventionTips":["Initialize all non-nullable POJO fields with defaults","Avoid mutating backing objects after wrapping in a Row","Align @DefaultSchema annotations with runtime nullability"],"tags":["java","apache-beam","schema","nullability","row"],"backgroundTag":"null-value-in-non-nullable-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}