{"record":{"id":"52513cf784afc066","repo":"apache/beam","slug":"unexpected-null-element-type-fielddescriptor-getname","errorCode":null,"errorMessage":"Unexpected null element type: \" + fieldDescriptor.getName()","messagePattern":"Unexpected null element type: \" \\+ fieldDescriptor\\.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":339,"sourceCode":"      } 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        }\n\n        return StreamSupport.stream(iterable.spliterator(), false)\n            .map(v -> toProtoValue(fieldDescriptor, iterableElementType, v))\n            .collect(Collectors.toList());\n      case MAP:\n        Map<Object, Object> map = (Map<Object, Object>) value;\n        @Nullable FieldType keyType = beamFieldType.getMapKeyType();\n        @Nullable FieldType valueType = beamFieldType.getMapValueType();\n        if (keyType == null) {\n          throw new RuntimeException(\"Unexpected null for key type: \" + fieldDescriptor.getName());\n        }\n        if (valueType == null) {\n          throw new RuntimeException(\n              \"Unexpected null for value type: \" + fieldDescriptor.getName());\n        }\n\n        return map.entrySet().stream()","sourceCodeStart":321,"sourceCodeEnd":357,"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#L321-L357","documentation":"toProtoValue converts Beam values into protobuf values per field. For ARRAY/ITERABLE typed fields it fetches the collection element type with getCollectionElementType(); a null result means the FieldType claims to be a collection but carries no element type, so per-element conversion is impossible and the converter throws, naming the proto field.","triggerScenarios":"toProtoValue for a field whose beamFieldType.getTypeName() is ARRAY or ITERABLE while beamFieldType.getCollectionElementType() returns null - malformed FieldType built without an element type, or an Iterable typed via reflection without element info.","commonSituations":"Schemas using Iterable fields inferred from raw/generic Java types (e.g. List without generics), hand-built FieldTypes with TypeName.ARRAY but no collection element, deserialized schemas losing element metadata.","solutions":["Use FieldType.array(elementType) (or FieldType.iterable(elementType)) with a concrete element type.","Replace raw java.util.List fields in schema classes with generic List<T> so inference captures the element type.","Validate the schema before the sink: assert getCollectionElementType() != null for all ARRAY/ITERABLE fields.","Catch the RuntimeException around toProtoValue and fail the record with a clear schema error."],"exampleFix":"// before\nFieldType arr = FieldType.builder().setType(TypeName.ARRAY).build();\n// after\nFieldType arr = FieldType.array(FieldType.string());","handlingStrategy":"validation","validationCode":"for (Schema.Field f : schema.getFields()) {\n  Schema.FieldType t = f.getType();\n  if ((t.getTypeName() == Schema.TypeName.ARRAY || t.getTypeName() == Schema.TypeName.ITERABLE)\n      && t.getCollectionElementType() == null) {\n    throw new IllegalArgumentException(\"Field \" + f.getName() + \" missing collection element type\");\n  }\n}","typeGuard":"boolean hasCollectionElementType(Schema.Field f) {\n  return (f.getType().getTypeName() != Schema.TypeName.ARRAY\n      && f.getType().getTypeName() != Schema.TypeName.ITERABLE)\n      || f.getType().getCollectionElementType() != null;\n}","tryCatchPattern":"try {\n  value = toProtoValue(fieldDescriptor, beamFieldType, v);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Unexpected null element type\")) {\n    throw new SchemaException(\"Array field lacks element type: \" + e.getMessage());\n  }\n  throw e;\n}","preventionTips":["Use FieldType.array(elementType), never bare TypeName.ARRAY","Avoid raw List fields in schema classes","Validate collection fields during schema construction"],"tags":["java","apache-beam","bigquery","array-type"],"backgroundTag":"internal-invariant-violation","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"}