{"record":{"id":"65047ca63089bbad","repo":"apache/beam","slug":"null-collection-element-type-at-field","errorCode":null,"errorMessage":"Null collection element type at field {}","messagePattern":"Null collection element type at field (.+?)","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/MutationUtils.java","lineNumber":324,"sourceCode":"      case ITERABLE:\n        addIterableToMutationBuilder(\n            mutationBuilder, row.getIterable(columnName), row.getSchema().getField(columnName));\n        break;\n      default:\n        throw new IllegalArgumentException(\n            String.format(\"Unsupported field type: %s\", fieldType.getTypeName()));\n    }\n  }\n\n  @SuppressWarnings(\"unchecked\")\n  private static void addIterableToMutationBuilder(\n      Mutation.WriteBuilder mutationBuilder,\n      @Nullable Iterable<Object> iterable,\n      Schema.Field field) {\n    String column = field.getName();\n    Schema.FieldType beamIterableType = field.getType().getCollectionElementType();\n    if (beamIterableType == null) {\n      throw new NullPointerException(\"Null collection element type at field \" + field.getName());\n    }\n    Schema.TypeName beamIterableTypeName = beamIterableType.getTypeName();\n    switch (beamIterableTypeName) {\n      case ROW:\n        if (iterable == null) {\n          mutationBuilder.set(column).toStructArray(beamTypeToSpannerType(beamIterableType), null);\n        } else {\n          mutationBuilder\n              .set(column)\n              .toStructArray(\n                  beamTypeToSpannerType(beamIterableType),\n                  StreamSupport.stream(iterable.spliterator(), false)\n                      .map(row -> beamRowToStruct((Row) row))\n                      .collect(toList()));\n        }\n        break;\n      case INT16:\n      case INT32:","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/MutationUtils.java#L306-L342","documentation":"addIterableToMutationBuilder needs the element type of an ITERABLE-typed field to pick the Spanner array type. If Schema.FieldType.getCollectionElementType() returns null, a NullPointerException is thrown with this message. This happens when a field is marked ITERABLE but was created without an element type.","triggerScenarios":"Writing a Beam Row to Spanner where a field's FieldType is an iterable/collection constructed without an element type (e.g. Schema.FieldType.iterable(...) given null or a malformed schema), so field.getType().getCollectionElementType() == null.","commonSituations":"Programmatically built schemas (or schemas deserialized from a logical plan) where the iterable element type was omitted; a schema evolution bug that stripped element type info.","solutions":["Fix the schema definition so every ITERABLE field specifies a concrete element type, e.g. Schema.FieldType.array(Schema.FieldType.STRING).","If the schema comes from another source (avro/proto inference), verify the inferred element type is present before writing.","Add a pre-write validation step that asserts each collection field has a non-null collection element type."],"exampleFix":"// before\nSchema.FieldType.iterable(null)\n// after\nSchema.FieldType.array(Schema.FieldType.INT64)","handlingStrategy":"validation","validationCode":"for (Schema.Field f : row.getSchema().getFields()) {\n  if (f.getType().getTypeName() == Schema.TypeName.ITERABLE\n      && f.getType().getCollectionElementType() == null) {\n    throw new IllegalStateException(\"Iterable field missing element type: \" + f.getName());\n  }\n}","typeGuard":null,"tryCatchPattern":"try { createMutationFromBeamRows(schema, row, table); } catch (NullPointerException e) { if (e.getMessage() != null && e.getMessage().contains(\"Null collection element type\")) { /* fix schema or skip row */ } else throw e; }","preventionTips":["Always build iterable fields with Schema.FieldType.array(elementType)","Validate programmatically constructed schemas before writes","Round-trip serialize schemas in tests to catch dropped element types"],"tags":["java","beam","spanner","null","schema"],"backgroundTag":"null-argument","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"}