{"record":{"id":"6099eecb80b30c56","repo":"apache/beam","slug":"collection-element-type-cannot-be-null","errorCode":null,"errorMessage":"Collection element type cannot be null.","messagePattern":"Collection element type cannot be null\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/firestore/FirestoreUtils.java","lineNumber":180,"sourceCode":"      case INT64:\n        return Value.newBuilder().setIntegerValue(((Number) value).longValue()).build();\n      case DOUBLE:\n        return Value.newBuilder().setDoubleValue(((Number) value).doubleValue()).build();\n      case BOOLEAN:\n        return Value.newBuilder().setBooleanValue((Boolean) value).build();\n      case DATETIME:\n        Instant instant = (Instant) value;\n        return Value.newBuilder()\n            .setTimestampValue(Timestamps.fromMillis(instant.getMillis()))\n            .build();\n      case BYTES:\n        return Value.newBuilder().setBytesValue(ByteString.copyFrom((byte[]) value)).build();\n      case ARRAY:\n      case ITERABLE:\n        ArrayValue.Builder arrayBuilder = ArrayValue.newBuilder();\n        FieldType elementType = fieldType.getCollectionElementType();\n        if (elementType == null) {\n          throw new IllegalArgumentException(\"Collection element type cannot be null.\");\n        }\n        for (Object item : (Iterable<?>) value) {\n          arrayBuilder.addValues(\n              item == null\n                  ? Value.newBuilder()\n                      .setNullValue(com.google.protobuf.NullValue.NULL_VALUE)\n                      .build()\n                  : javaToValue(item, elementType));\n        }\n        return Value.newBuilder().setArrayValue(arrayBuilder.build()).build();\n      case MAP:\n        MapValue.Builder mapBuilder = MapValue.newBuilder();\n        FieldType valueType = fieldType.getMapValueType();\n        if (valueType == null) {\n          throw new IllegalArgumentException(\"Map value type cannot be null.\");\n        }\n        for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {\n          Object mapValue = entry.getValue();","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/firestore/FirestoreUtils.java#L162-L198","documentation":"javaToValue converts Java objects to Firestore Value protos using the Beam schema FieldType. When the field is ARRAY or ITERABLE, the element type from fieldType.getCollectionElementType() is required to recursively convert items; if it is null the converter refuses and throws IllegalArgumentException, because it cannot know how to serialize the elements.","triggerScenarios":"Writing Rows to Firestore where a field was declared as an array/iterable type but its FieldType was constructed without an element type — e.g. FieldType.iterable(...) composed incorrectly or a programmatically built FieldType missing element metadata.","commonSituations":"Building schemas dynamically with reflection and forgetting to specify the element type; schemas created from deserialized/incomplete type metadata; using FieldType.of(TypeName.ARRAY) directly instead of FieldType.iterable(elementType).","solutions":["Create array fields with FieldType.iterable(FieldType) supplying a concrete element type","Verify the Schema's field types with field.getType().getCollectionElementType() before writing","Use Schema.builder().addArrayField(name, elementType) rather than manual FieldType construction"],"exampleFix":"// before\nFieldType bad = FieldType.of(TypeName.ARRAY); // no element type\n// after\nFieldType good = FieldType.iterable(FieldType.STRING);","handlingStrategy":"validation","validationCode":"FieldType ft = schema.getField(name).getType();\nif ((ft.getTypeName() == TypeName.ARRAY || ft.getTypeName() == TypeName.ITERABLE)\n    && ft.getCollectionElementType() == null) {\n  throw new IllegalStateException(\"Array field '\" + name + \"' lacks element type\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use FieldType.iterable(elementType) or Schema.builder().addArrayField","Validate schemas once at pipeline construction time","Add schema sanity checks in unit tests"],"tags":["java","apache-beam","firestore","schema-validation"],"backgroundTag":"missing-required-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"}