{"record":{"id":"e64317520509fd9a","repo":"apache/beam","slug":"null-value-found-for-field-that-doesn-t-support-nulls","errorCode":null,"errorMessage":"Null value found for field that doesn't support nulls.","messagePattern":"Null value found for field that doesn't support nulls\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaTranslation.java","lineNumber":580,"sourceCode":"    return builder.build();\n  }\n\n  public static Object rowFromProto(SchemaApi.Row row, FieldType fieldType) {\n    Row.Builder builder = Row.withSchema(fieldType.getRowSchema());\n    for (int i = 0; i < row.getValuesCount(); ++i) {\n      builder.addValue(\n          fieldValueFromProto(fieldType.getRowSchema().getField(i).getType(), row.getValues(i)));\n    }\n    return builder.build();\n  }\n\n  static SchemaApi.FieldValue fieldValueToProto(FieldType fieldType, Object value) {\n    FieldValue.Builder builder = FieldValue.newBuilder();\n    if (value == null) {\n      if (fieldType.getNullable()) {\n        return builder.build();\n      } else {\n        throw new RuntimeException(\"Null value found for field that doesn't support nulls.\");\n      }\n    }\n\n    switch (fieldType.getTypeName()) {\n      case ARRAY:\n        return builder\n            .setArrayValue(\n                arrayValueToProto(fieldType.getCollectionElementType(), (Iterable) value))\n            .build();\n      case ITERABLE:\n        return builder\n            .setIterableValue(\n                iterableValueToProto(fieldType.getCollectionElementType(), (Iterable) value))\n            .build();\n      case MAP:\n        return builder\n            .setMapValue(\n                mapToProto(fieldType.getMapKeyType(), fieldType.getMapValueType(), (Map) value))","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaTranslation.java#L562-L598","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nFieldType fieldType = FieldType.STRING; // non-nullable, row value is null\n// after\nFieldType fieldType = FieldType.STRING.withNullable(true);","handlingStrategy":"validation","validationCode":"for (Field f : schema.getFields()) { if (!f.getType().getNullable() && row.getValue(f.getName()) == null) throw new IllegalArgumentException(\"null in non-nullable field \" + f.getName()); }","typeGuard":"boolean isRowEncodable(Row row, Schema schema) { return schema.getFields().stream().allMatch(f -> f.getType().getNullable() || row.getValue(f.getName()) != null); }","tryCatchPattern":"try { rowToProto(row); } catch (RuntimeException e) { if (e.getMessage().contains(\"Null value found\")) { /* repair row or relax schema */ } else { throw e; } }","preventionTips":["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"],"tags":["java","null","schema","serialization"],"backgroundTag":"schema-validation-failed","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"}