apache/beam · error · IllegalArgumentException

is not a ParameterizedType

Error message

 is not a ParameterizedType

What it means

CoderRegistry.getDefaultCoders resolves the supertype of subClass up to baseClass and expects it to be a ParameterizedType (the base class must carry generic type arguments). If the resolved supertype is a raw Class — e.g. DoFn was subclassed without type parameters — it throws IllegalArgumentException '<type> is not a ParameterizedType'.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/coders/CoderRegistry.java:427

   * Coder} for a particular type variable cannot be inferred. Instead, it results in a {@code null}
   * in the array. It is the responsibility of the caller (usually {@link
   * #getCoderFromTypeDescriptor} to extract the desired coder or throw a {@link
   * CannotProvideCoderException} when appropriate.
   *
   * @param subClass the concrete type whose specializations are being inferred
   * @param baseClass the base type, a parameterized class
   * @param knownCoders an array corresponding to the set of base class type parameters. Each entry
   *     can be either a {@link Coder} (in which case it will be used for inference) or {@code null}
   *     (in which case it will be inferred). May be {@code null} to indicate the entire set of
   *     parameters should be inferred.
   * @throws IllegalArgumentException if baseClass doesn't have type parameters or if the length of
   *     {@code knownCoders} is not equal to the number of type parameters of {@code baseClass}.
   */
  private <T> Coder<?>[] getDefaultCoders(
      Class<? extends T> subClass, Class<T> baseClass, @Nullable Coder<?>[] knownCoders) {
    Type type = TypeDescriptor.of(subClass).getSupertype(baseClass).getType();
    if (!(type instanceof ParameterizedType)) {
      throw new IllegalArgumentException(type + " is not a ParameterizedType");
    }
    ParameterizedType parameterizedType = (ParameterizedType) type;
    Type[] typeArgs = parameterizedType.getActualTypeArguments();
    if (knownCoders == null) {
      knownCoders = new Coder<?>[typeArgs.length];
    } else if (typeArgs.length != knownCoders.length) {
      throw new IllegalArgumentException(
          String.format(
              "Class %s has %d parameters, but %d coders are requested.",
              baseClass.getCanonicalName(), typeArgs.length, knownCoders.length));
    }

    SetMultimap<Type, Coder<?>> context = HashMultimap.create();
    for (int i = 0; i < knownCoders.length; i++) {
      if (knownCoders[i] != null) {
        try {
          verifyCompatible(knownCoders[i], typeArgs[i]);
        } catch (IncompatibleCoderException exn) {

View on GitHub (pinned to 12126d8942)

Solutions

  1. Parameterize the base class in the extends clause: class MyFn extends DoFn<String, Long>
  2. Ensure the baseClass argument passed to getDefaultCoders is the generic supertype actually used by subClass
  3. If the type is genuinely non-generic, do not use getDefaultCoders — register or supply the coder explicitly instead

Example fix

// before
class MyFn extends DoFn { ... } // raw type
// after
class MyFn extends DoFn<String, Long> { ... }
Defensive patterns

Strategy: type-guard

Validate before calling

Type sup = TypeDescriptor.of(subClass).getSupertype(baseClass).getType();
if (!(sup instanceof ParameterizedType)) throw new IllegalStateException("Parameterize " + baseClass.getSimpleName());

Type guard

boolean isParameterized = TypeDescriptor.of(subClass).getSupertype(baseClass).getType() instanceof ParameterizedType;

Prevention

When it happens

Trigger: Subclassing a generic base (e.g. DoFn or CombineFn) without supplying type arguments (raw subclass), then calling getDefaultCoders/getDefaultOutputCoder; passing a baseClass that is not actually a generic supertype of subClass.

Common situations: Raw-type DoFn subclasses written before generics were considered; Scala/other-JVM classes erasing to raw types; refactorings that removed <InputT, OutputT> from the extends clause.

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/22f5fd0e35d19cd6. Report an issue: GitHub.