{"record":{"id":"dea2242c22c14f9b","repo":"apache/beam","slug":"received-null-value-for-non-nullable-field-fielddescriptor-dea224","errorCode":null,"errorMessage":"Received null value for non-nullable field \" + fieldDescriptor.getName()","messagePattern":"Received null value for non-nullable field \" \\+ fieldDescriptor\\.getName\\(\\)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BeamRowToStorageApiProto.java","lineNumber":322,"sourceCode":"      }\n    }\n    if (field.getDescription() != null) {\n      builder = builder.setDescription(field.getDescription());\n    }\n    return builder.build();\n  }\n\n  @Nullable\n  private static Object messageValueFromRowValue(\n      FieldDescriptor fieldDescriptor, Field beamField, int index, Row row) {\n    @Nullable Object value = row.getValue(index);\n    if (value == null) {\n      if (fieldDescriptor.isOptional()) {\n        return null;\n      } else if (fieldDescriptor.isRepeated()) {\n        return Collections.emptyList();\n      } else {\n        throw new IllegalArgumentException(\n            \"Received null value for non-nullable field \" + fieldDescriptor.getName());\n      }\n    }\n    return toProtoValue(fieldDescriptor, beamField.getType(), value);\n  }\n\n  private static Object toProtoValue(\n      FieldDescriptor fieldDescriptor, FieldType beamFieldType, Object value) {\n    switch (beamFieldType.getTypeName()) {\n      case ROW:\n        return messageFromBeamRow(fieldDescriptor.getMessageType(), (Row) value, null, -1);\n      case ARRAY:\n      case ITERABLE:\n        Iterable<Object> iterable = (Iterable<Object>) value;\n        @Nullable FieldType iterableElementType = beamFieldType.getCollectionElementType();\n        if (iterableElementType == null) {\n          throw new RuntimeException(\"Unexpected null element type: \" + fieldDescriptor.getName());\n        }","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BeamRowToStorageApiProto.java#L304-L340","documentation":"messageValueFromRowValue converts a Row cell into a protobuf value for the Storage Write path. If the value is null but the target FieldDescriptor is neither optional (nullable) nor repeated, the row violates the schema's nullability and an IllegalArgumentException is thrown naming the field. BigQuery-required fields cannot receive null.","triggerScenarios":"Writing a Row via messageFromBeamRow/BeamRowToStorageApiProto where a field declared non-nullable in the Beam schema (getNullable()==false) contains an actual null value - e.g. a missing cell in a partially-filled row.","commonSituations":"Rows built via Row.withFieldNames without values for every field; upstream joins/coGroup producing nulls; data source with missing values while schema declares REQUIRED.","solutions":["Declare the field nullable: FieldType.string().withNullable(true), so null maps to an unset proto field.","Fill nulls before writing: use a DoFn/MapElements to replace null with a default (empty string, 0, sentinel).","Filter out rows that violate nullability before the sink.","Ensure the schema used for the Row matches the schema used to build the TableSchema (same generated class version)."],"exampleFix":"// before\nSchema.Field f = Schema.Field.of(\"name\", Schema.FieldType.STRING); // non-null\n// after\nSchema.Field f = Schema.Field.of(\"name\", Schema.FieldType.STRING.withNullable(true));","handlingStrategy":"validation","validationCode":"for (Schema.Field f : schema.getFields()) {\n  if (!f.getType().getNullable() && row.getValue(f.getName()) == null) {\n    throw new IllegalArgumentException(\"Row field \" + f.getName() + \" is null but schema marks it non-nullable\");\n  }\n}","typeGuard":"boolean satisfiesNullability(Row row, Schema schema) {\n  return schema.getFields().stream()\n      .noneMatch(f -> !f.getType().getNullable() && row.getValue(f.getName()) == null);\n}","tryCatchPattern":"try {\n  DynamicMessage msg = messageFromBeamRow(descriptor, schema, row, unknownFields, -1);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Received null value for non-nullable field\")) {\n    row = fillDefaults(row);\n    // retry once\n  } else { throw e; }\n}","preventionTips":["Declare fields nullable when data can be missing","Fill nulls with defaults in a DoFn before the sink","Filter invalid rows into a dead-letter PCollection","Keep generated record classes and table schema in sync"],"tags":["java","apache-beam","bigquery","nullability"],"backgroundTag":"null-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}