apache/beam · error · RuntimeException

Map type is not parameterized! {}

Error message

Map type is not parameterized! {}

What it means

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.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ReflectUtils.java:243

        checkArgument(params.length == 1);
        componentType = TypeDescriptor.of(params[0]);
      } else {
        throw new RuntimeException("Collection parameter is not parameterized!");
      }
    }
    return componentType;
  }

  public static TypeDescriptor getMapType(TypeDescriptor valueType, int index) {
    TypeDescriptor mapType = null;
    if (valueType.isSubtypeOf(TypeDescriptor.of(Map.class))) {
      TypeDescriptor<Collection<?>> map = valueType.getSupertype(Map.class);
      if (map.getType() instanceof ParameterizedType) {
        ParameterizedType ptype = (ParameterizedType) map.getType();
        java.lang.reflect.Type[] params = ptype.getActualTypeArguments();
        mapType = TypeDescriptor.of(params[index]);
      } else {
        throw new RuntimeException("Map type is not parameterized! " + map);
      }
    }
    return mapType;
  }

  public static TypeDescriptor boxIfPrimitive(TypeDescriptor typeDescriptor) {
    return typeDescriptor.getRawType().isPrimitive()
        ? TypeDescriptor.of(Primitives.wrap(typeDescriptor.getRawType()))
        : typeDescriptor;
  }
}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Parameterize the field: Map<String, Integer> instead of raw Map.
  2. Provide a TypeDescriptor<Map<String, Integer>> explicitly when building the schema/coder.
  3. If a custom Map subclass is used, declare it with generics, e.g. class MyMap extends HashMap<String, String> {}, so the supertype is parameterized.

Example fix

// before
private Map attributes; // raw map
// after
private Map<String, String> attributes;
Defensive patterns

Strategy: type-guard

Validate before calling

TypeDescriptor<?> td = TypeDescriptor.of(MyPojo.class).getField("attributes").getType();
if (Map.class.isAssignableFrom(td.getRawType()) && !(td.getType() instanceof java.lang.reflect.ParameterizedType)) {
  throw new IllegalStateException("Map field must declare key and value types");
}

Type guard

// returns the key/value descriptor at index, or null when the map is raw (would trigger the error)
static <M extends Map<?, ?>> TypeDescriptor<?> mapTypeOrNull(TypeDescriptor<M> td, int index) {
  return td.getType() instanceof java.lang.reflect.ParameterizedType
      ? td.resolveType(((java.lang.reflect.ParameterizedType) td.getType()).getActualTypeArguments()[index])
      : null;
}

Prevention

When it happens

Trigger: 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).

Common situations: Raw Map fields in legacy POJOs, fields declared as Map via raw Class tokens, or custom Map implementations declared without generics.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/38a857506c245f46. Report an issue: GitHub.