{"record":{"id":"6ad0a43a4cad33a6","repo":"apache/beam","slug":"collection-element-type-cannot-be-null-for-type-fieldtype","errorCode":null,"errorMessage":"Collection element type cannot be null for type: \" + fieldType","messagePattern":"Collection element type cannot be null for type: \" \\+ fieldType","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/mongodb/src/main/java/org/apache/beam/sdk/io/mongodb/MongoDbUtils.java","lineNumber":164,"sourceCode":"        } else if (value instanceof byte[]) {\n          return (byte[]) value;\n        } else {\n          return value.toString().getBytes(java.nio.charset.StandardCharsets.UTF_8);\n        }\n      case ARRAY:\n      case ITERABLE:\n        if (!(value instanceof Iterable)) {\n          throw new IllegalArgumentException(\n              \"Expected Iterable for type \"\n                  + fieldType\n                  + \", but got: \"\n                  + value.getClass().getName());\n        }\n        Iterable<?> iterable = (Iterable<?>) value;\n        List<@Nullable Object> rowList = new ArrayList<>();\n        FieldType elementType = fieldType.getCollectionElementType();\n        if (elementType == null) {\n          throw new IllegalArgumentException(\n              \"Collection element type cannot be null for type: \" + fieldType);\n        }\n        for (Object item : iterable) {\n          rowList.add(convertFromBsonValue(item, elementType));\n        }\n        return rowList;\n      case MAP:\n        if (!(value instanceof Map)) {\n          throw new IllegalArgumentException(\n              \"Expected Map for type \" + fieldType + \", but got: \" + value.getClass().getName());\n        }\n        Map<?, ?> map = (Map<?, ?>) value;\n        Map<String, @Nullable Object> rowMap = new HashMap<>();\n        FieldType valueType = fieldType.getMapValueType();\n        if (valueType == null) {\n          throw new IllegalArgumentException(\n              \"Map value type cannot be null for type: \" + fieldType);\n        }","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/mongodb/src/main/java/org/apache/beam/sdk/io/mongodb/MongoDbUtils.java#L146-L182","documentation":"When converting a BSON iterable/array into a Beam Row list, convertFromBsonValue needs the collection's element type from the schema FieldType. If fieldType.getCollectionElementType() returns null, the converter cannot know how to convert elements and throws this IllegalArgumentException.","triggerScenarios":"A Beam schema field declared as ARRAY/ITERABLE without a concrete element type (missing type parameter / null collection element type) encountered during BSON-to-Row conversion.","commonSituations":"Programmatically built schemas where the collection element type was never set, or reflection-based schema inference failing to resolve the element generic type.","solutions":["Define the array field with an explicit element type in the schema (e.g., ARRAY<STRING> not bare ARRAY)","Rebuild the schema using Schema.Field.of(name, FieldType.array(FieldType.string())) so elementType is non-null","Avoid raw/unparameterized collection types when generating the schema"],"exampleFix":"// before\nSchema.Field.of(\"items\", FieldType.array(null)); // elementType null -> throws\n// after\nSchema.Field.of(\"items\", FieldType.array(FieldType.STRING));","handlingStrategy":"validation","validationCode":"FieldType ft = schema.getField(\"items\").getType();\nif ((ft.getTypeName() == Schema.TypeName.ARRAY || ft.getTypeName() == Schema.TypeName.ITERABLE)\n    && ft.getCollectionElementType() == null) {\n  throw new IllegalArgumentException(\"Array field 'items' must declare an element type\");\n}","typeGuard":"static boolean hasElementType(FieldType fieldType) {\n  return fieldType.getCollectionElementType() != null;\n}","tryCatchPattern":"try {\n  Row row = MongoDbUtils.toRow(doc, schema);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Collection element type cannot be null\")) {\n    // rebuild schema with explicit element types\n  }\n}","preventionTips":["Always parameterize array/iterable schema fields with a concrete element FieldType","Avoid raw collection types in POJOs used for schema inference","Validate programmatically built schemas (all collection fields have element types) before use"],"tags":["java","apache-beam","mongodb","schema","nullable-type"],"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-20T03:17:13.778Z"}