{"record":{"id":"7eb8664b7485aaf5","repo":"apache/beam","slug":"unexpected-null-element-type-on-field-getname","errorCode":null,"errorMessage":"Unexpected null element type on \" + field.getName()","messagePattern":"Unexpected null element type on \" \\+ field\\.getName\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BeamRowToStorageApiProto.java","lineNumber":225,"sourceCode":"    }\n    builder = builder.setName(field.getName().toLowerCase());\n\n    switch (field.getType().getTypeName()) {\n      case ROW:\n        @Nullable Schema rowSchema = field.getType().getRowSchema();\n        if (rowSchema == null) {\n          throw new RuntimeException(\"Unexpected null schema!\");\n        }\n        builder = builder.setType(TableFieldSchema.Type.STRUCT);\n        for (Schema.Field nestedField : rowSchema.getFields()) {\n          builder = builder.addFields(fieldDescriptorFromBeamField(nestedField));\n        }\n        break;\n      case ARRAY:\n      case ITERABLE:\n        @Nullable FieldType elementType = field.getType().getCollectionElementType();\n        if (elementType == null) {\n          throw new RuntimeException(\"Unexpected null element type on \" + field.getName());\n        }\n        TypeName containedTypeName =\n            Preconditions.checkNotNull(\n                elementType.getTypeName(),\n                \"Null type name found in contained type at %s\",\n                field.getName());\n        Preconditions.checkState(\n            !(containedTypeName.isCollectionType() || containedTypeName.isMapType()),\n            \"Nested container types are not supported by BigQuery. Field %s contains a type %s\",\n            field.getName(),\n            containedTypeName.name());\n        TableFieldSchema elementFieldSchema =\n            fieldDescriptorFromBeamField(Field.of(field.getName(), elementType));\n        builder = builder.setType(elementFieldSchema.getType());\n        if (elementFieldSchema.hasTimestampPrecision()) {\n          builder = builder.setTimestampPrecision(elementFieldSchema.getTimestampPrecision());\n        }\n        builder.addAllFields(elementFieldSchema.getFieldsList());","sourceCodeStart":207,"sourceCodeEnd":243,"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#L207-L243","documentation":"fieldDescriptorFromBeamField, for ARRAY or ITERABLE fields, calls field.getType().getCollectionElementType() and throws \"Unexpected null element type on <field name>\" when null. A collection-typed FieldType must declare its element type to build the BigQuery REPEATED field schema.","triggerScenarios":"A Beam Schema field declared ARRAY/ITERABLE without an element type (e.g. FieldType.of(TypeName.ARRAY) constructed manually), then written to BigQuery via Storage API","commonSituations":"Programmatic schema construction, schema inference frameworks emitting bare collection type names, or schemas built before Beam enforced element-type arguments.","solutions":["Create collection fields with an element type: Schema.FieldType.array(elementType) or iterable(elementType)","Validate all collection fields' getCollectionElementType() before invoking the write","Fix schema-inference code to always pass the contained type","Check the named field (in the message) to locate the malformed schema entry"],"exampleFix":"// before\nSchema.FieldType listType = Schema.FieldType.of(TypeName.ARRAY); // no element\n// after\nSchema.FieldType listType = Schema.FieldType.array(Schema.FieldType.STRING);","handlingStrategy":"validation","validationCode":"// Java\nfor (Schema.Field f : beamSchema.getFields()) {\n  TypeName tn = f.getType().getTypeName();\n  if ((tn == TypeName.ARRAY || tn == TypeName.ITERABLE) && f.getType().getCollectionElementType() == null) {\n    throw new IllegalStateException(\"Collection field without element type: \" + f.getName());\n  }\n}","typeGuard":"// Java\nFieldType el = fieldType.getCollectionElementType();\nif (el != null) { /* safe to map element schema */ }","tryCatchPattern":"// Java\ntry {\n  descriptor = BeamRowToStorageApiProto.protoTableSchemaFromBeamSchema(beamSchema);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Unexpected null element type on\")) {\n    // fix the named field's element type\n  }\n  throw e;\n}","preventionTips":["Build collections with Schema.FieldType.array(el)/iterable(el), never raw ARRAY type names","Run a schema lint in tests before each release","Fix inference code to always carry the contained element type"],"tags":["java","bigquery","beam-schema","collection"],"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-20T03:17:13.778Z"}