{"record":{"id":"5823dac4238c1992","repo":"apache/beam","slug":"unexpected-null-element-type-for-the-map-s-value-on-field","errorCode":null,"errorMessage":"Unexpected null element type for the map's value on \" + field.getName()","messagePattern":"Unexpected null element type for the map's value on \" \\+ field\\.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":280,"sourceCode":"          type = TableFieldSchema.Type.TIMESTAMP;\n          builder.setTimestampPrecision(Int64Value.newBuilder().setValue(12L).build());\n        } else {\n          type = LOGICAL_TYPES.get(logicalType.getIdentifier());\n          if (type == null) {\n            throw new RuntimeException(\"Unsupported logical type \" + field.getType());\n          }\n        }\n        builder = builder.setType(type);\n        break;\n      case MAP:\n        @Nullable FieldType keyType = field.getType().getMapKeyType();\n        @Nullable FieldType valueType = field.getType().getMapValueType();\n        if (keyType == null) {\n          throw new RuntimeException(\n              \"Unexpected null element type for the map's key on \" + field.getName());\n        }\n        if (valueType == null) {\n          throw new RuntimeException(\n              \"Unexpected null element type for the map's value on \" + field.getName());\n        }\n\n        builder =\n            builder\n                .setType(TableFieldSchema.Type.STRUCT)\n                .addFields(fieldDescriptorFromBeamField(Field.of(\"key\", keyType)))\n                .addFields(fieldDescriptorFromBeamField(Field.of(\"value\", valueType)))\n                .setMode(TableFieldSchema.Mode.REPEATED);\n        break;\n      default:\n        @Nullable\n        TableFieldSchema.Type primitiveType = PRIMITIVE_TYPES.get(field.getType().getTypeName());\n        if (primitiveType == null) {\n          throw new RuntimeException(\"Unsupported type \" + field.getType());\n        }\n        builder = builder.setType(primitiveType);\n    }","sourceCodeStart":262,"sourceCodeEnd":298,"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#L262-L298","documentation":"The mirror of the key-type check: while mapping a MAP field to a repeated key/value STRUCT for BigQuery, the map's value type (getMapValueType()) is null. The converter cannot build the key/value struct fields without it, so it throws an IllegalArgumentException-style RuntimeException naming the offending field.","triggerScenarios":"fieldDescriptorFromBeamField, case MAP, where field.getType().getMapValueType() returns null for field field.getName() - typically a FieldType of TypeName.MAP built without a value type.","commonSituations":"Hand-assembled or reflection-derived Beam schemas missing the value type; custom sources producing partial map FieldTypes; schema evolution tools dropping map value metadata.","solutions":["Construct the map field with FieldType.map(keyType, valueType) supplying a concrete value type.","Pre-validate the schema: reject any MAP field with null getMapValueType() before invoking the BigQuery sink.","Regenerate the schema from the actual data (e.g. via Schemainferencing) instead of reusing a damaged one.","Catch the RuntimeException around schema conversion and report which field is malformed."],"exampleFix":"// before\nFieldType bad = FieldType.builder().setType(TypeName.MAP).setMapKeyType(FieldType.string()).build();\n// after\nFieldType ok = FieldType.map(FieldType.string(), FieldType.string());","handlingStrategy":"validation","validationCode":"schema.getFields().stream()\n  .filter(f -> f.getType().getTypeName() == Schema.TypeName.MAP)\n  .forEach(f -> {\n    if (f.getType().getMapValueType() == null)\n      throw new IllegalArgumentException(\"Map field \" + f.getName() + \" missing value type\");\n  });","typeGuard":"boolean hasMapValueType(Schema.Field f) {\n  return f.getType().getTypeName() != Schema.TypeName.MAP || f.getType().getMapValueType() != null;\n}","tryCatchPattern":"try {\n  protoTableSchemaFromBeamSchema(schema);\n} catch (RuntimeException e) {\n  if (e.getMessage().contains(\"null element type for the map's value\")) {\n    throw new SchemaException(\"Map field without value type: \" + e.getMessage());\n  }\n  throw e;\n}","preventionTips":["Use FieldType.map(k, v) for every map field","Prefer generic Map<K,V> types in schema classes","Unit-test schema conversion for every record type used"],"tags":["java","apache-beam","bigquery","map-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"}