{"record":{"id":"4bdd5974f306436c","repo":"apache/beam","slug":"map-value-type-cannot-be-null-for-type-fieldtype","errorCode":null,"errorMessage":"Map value type cannot be null for type: \" + fieldType","messagePattern":"Map value 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":180,"sourceCode":"        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        }\n        for (Map.Entry<?, ?> entry : map.entrySet()) {\n          rowMap.put(\n              String.valueOf(entry.getKey()), convertFromBsonValue(entry.getValue(), valueType));\n        }\n        return rowMap;\n      case ROW:\n        Schema rowSchema = fieldType.getRowSchema();\n        if (rowSchema == null) {\n          throw new IllegalArgumentException(\"Row schema cannot be null for type: \" + fieldType);\n        }\n        if (value instanceof Map) {\n          return toRow((Map<?, ?>) value, rowSchema);\n        } else {\n          throw new IllegalArgumentException(\n              \"Cannot convert value of type \"\n                  + (value != null ? value.getClass().getName() : \"null\")","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/mongodb/src/main/java/org/apache/beam/sdk/io/mongodb/MongoDbUtils.java#L162-L198","documentation":"After confirming the value is a Map, convertFromBsonValue asks FieldType.getMapValueType() to know how to convert each map value. A MAP FieldType in Beam always has an element type; if this returns null the FieldType was constructed inconsistently (a map type with no declared value type), so conversion cannot proceed safely.","triggerScenarios":"A FieldType.map(...) was built or deserialized without a value type, or a hand-assembled Schema contains a MAP FieldType whose mapValueType is null. Triggered whenever a Map value is converted via toRow/convertFromBsonValue.","commonSituations":"Programmatic schema construction mistakes; schemas built via reflection with generics erased (raw Map without type parameters); serialized schemas round-tripped through formats that lose the map value type.","solutions":["Declare the map value type explicitly: FieldType.map(FieldType.STRING) (or the appropriate value FieldType) when building the schema.","If generics are erased, build the schema with an explicit Field list instead of relying on automatic schema inference from a raw Map class.","Verify the SchemaRegistry-generated schema (e.g. getSchema(Class)) resolves the Map's generic parameter; use TypeDescriptor with full generics."],"exampleFix":"// before\nFieldType t = FieldType.map(null);\n// after\nFieldType t = FieldType.map(FieldType.STRING);","handlingStrategy":"validation","validationCode":"schema.getFields().forEach(f -> {\n  if (f.getType().getTypeName().equals(TypeName.MAP) && f.getType().getMapValueType() == null) {\n    throw new IllegalStateException(\"MAP field without value type: \" + f.getName());\n  }\n});","typeGuard":null,"tryCatchPattern":"try {\n  Row row = toRow(doc, schema);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Map value type cannot be null\")) {\n    throw new SchemaConfigurationException(\"Declare map value types explicitly\");\n  }\n  throw e;\n}","preventionTips":["Always use FieldType.map(valueType) with an explicit value type.","Avoid raw Map classes in schema-inferred POJOs; use parameterized generics.","Validate schemas in unit tests before running pipelines."],"tags":["mongodb","apache-beam","schema","null"],"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"}