{"record":{"id":"38a857506c245f46","repo":"apache/beam","slug":"map-type-is-not-parameterized","errorCode":null,"errorMessage":"Map type is not parameterized! {}","messagePattern":"Map type is not parameterized! (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ReflectUtils.java","lineNumber":243,"sourceCode":"        checkArgument(params.length == 1);\n        componentType = TypeDescriptor.of(params[0]);\n      } else {\n        throw new RuntimeException(\"Collection parameter is not parameterized!\");\n      }\n    }\n    return componentType;\n  }\n\n  public static TypeDescriptor getMapType(TypeDescriptor valueType, int index) {\n    TypeDescriptor mapType = null;\n    if (valueType.isSubtypeOf(TypeDescriptor.of(Map.class))) {\n      TypeDescriptor<Collection<?>> map = valueType.getSupertype(Map.class);\n      if (map.getType() instanceof ParameterizedType) {\n        ParameterizedType ptype = (ParameterizedType) map.getType();\n        java.lang.reflect.Type[] params = ptype.getActualTypeArguments();\n        mapType = TypeDescriptor.of(params[index]);\n      } else {\n        throw new RuntimeException(\"Map type is not parameterized! \" + map);\n      }\n    }\n    return mapType;\n  }\n\n  public static TypeDescriptor boxIfPrimitive(TypeDescriptor typeDescriptor) {\n    return typeDescriptor.getRawType().isPrimitive()\n        ? TypeDescriptor.of(Primitives.wrap(typeDescriptor.getRawType()))\n        : typeDescriptor;\n  }\n}\n","sourceCodeStart":225,"sourceCodeEnd":255,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ReflectUtils.java#L225-L255","documentation":"ReflectUtils.getMapType extracts the key or value type (by index) of a Map-typed field by looking up its Map supertype's type arguments. If the map type is not parameterized (raw Map), the type arguments cannot be read and this RuntimeException is thrown with the offending type in the message.","triggerScenarios":"Schema inference on a POJO field declared as raw Map (no key/value generics), or a subtype whose resolved Map supertype lost its type parameters, calling getMapType(valueType, index) with index 0 (key) or 1 (value).","commonSituations":"Raw Map fields in legacy POJOs, fields declared as Map via raw Class tokens, or custom Map implementations declared without generics.","solutions":["Parameterize the field: Map<String, Integer> instead of raw Map.","Provide a TypeDescriptor<Map<String, Integer>> explicitly when building the schema/coder.","If a custom Map subclass is used, declare it with generics, e.g. class MyMap extends HashMap<String, String> {}, so the supertype is parameterized."],"exampleFix":"// before\nprivate Map attributes; // raw map\n// after\nprivate Map<String, String> attributes;","handlingStrategy":"type-guard","validationCode":"TypeDescriptor<?> td = TypeDescriptor.of(MyPojo.class).getField(\"attributes\").getType();\nif (Map.class.isAssignableFrom(td.getRawType()) && !(td.getType() instanceof java.lang.reflect.ParameterizedType)) {\n  throw new IllegalStateException(\"Map field must declare key and value types\");\n}","typeGuard":"// returns the key/value descriptor at index, or null when the map is raw (would trigger the error)\nstatic <M extends Map<?, ?>> TypeDescriptor<?> mapTypeOrNull(TypeDescriptor<M> td, int index) {\n  return td.getType() instanceof java.lang.reflect.ParameterizedType\n      ? td.resolveType(((java.lang.reflect.ParameterizedType) td.getType()).getActualTypeArguments()[index])\n      : null;\n}","tryCatchPattern":null,"preventionTips":["Declare map fields with both key and value generics: Map<String, Integer>.","For custom Map subclasses, preserve generics (class MyMap extends HashMap<String, String> {}).","Validate all schema POJO field types are fully parameterized in a startup check."],"tags":["java","generics","reflection","beam-schema"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}