{"record":{"id":"de91e440dca5d1cc","repo":"apache/beam","slug":"row-schema-cannot-be-null-for-type-fieldtype","errorCode":null,"errorMessage":"Row schema cannot be null for type: \" + fieldType","messagePattern":"Row schema 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":191,"sourceCode":"          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\")\n                  + \" to Row\");\n        }\n      default:\n        throw new IllegalArgumentException(\"Unsupported field type: \" + fieldType);\n    }\n  }\n}\n","sourceCodeStart":173,"sourceCodeEnd":206,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/mongodb/src/main/java/org/apache/beam/sdk/io/mongodb/MongoDbUtils.java#L173-L206","documentation":"convertFromBsonValue hit a ROW FieldType but the FieldType carries no nested Schema (getRowSchema() returned null). Beam ROW types require an embedded Schema describing the nested fields; without it the converter cannot build a Row, so it throws IllegalArgumentException.","triggerScenarios":"A nested/struct field was declared as FieldType ROW (e.g. via FieldType.row(null) or an incompletely built schema) and a nested document arrives from MongoDB during toRow/convertFromBsonValue.","commonSituations":"Hand-built schemas where the nested Schema was forgotten; schemas built via Schema.builder() where the row type was added before its schema existed; schema deserialization that dropped nested schemas.","solutions":["Build the nested field with Schema.of(Field...) wrapped: FieldType.row(Schema.of(Field.of(\"name\", FieldType.STRING), ...)).","If using inferred schemas, ensure the nested Java class is annotated/registered (DefaultSchema, @SchemaCreate) so its Schema resolves non-null.","Replace the ROW field with MAP if the nested document has dynamic keys and no fixed schema."],"exampleFix":"// before\nField.of(\"address\", FieldType.row(null))\n// after\nField.of(\"address\", FieldType.row(Schema.of(Field.of(\"city\", FieldType.STRING))))","handlingStrategy":"validation","validationCode":"schema.getFields().forEach(f -> {\n  if (f.getType().getTypeName().equals(TypeName.ROW) && f.getType().getRowSchema() == null) {\n    throw new IllegalStateException(\"ROW field without schema: \" + 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(\"Row schema cannot be null\")) {\n    throw new SchemaConfigurationException(\"Nested field missing Schema\");\n  }\n  throw e;\n}","preventionTips":["Always build ROW fields with FieldType.row(Schema.of(...)).","Use schema inference from annotated classes instead of hand-built rows where possible.","Add a schema sanity check test that walks all nested fields."],"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"}