apache/flink · error · InvalidTypesException

The given type {} is not a parameterized type.

Error message

The given type {} is not a parameterized type.

What it means

Thrown by TypeExtractionUtils.extractTypeArgument when the provided Type is not an instance of ParameterizedType. This means the type does not carry runtime generic information (it is a raw Class or a TypeVariable without resolved bindings). Type argument extraction requires a ParameterizedType so that getActualTypeArguments() returns concrete type bindings.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractionUtils.java:222

     * @throws InvalidTypesException if the given type does not have any type arguments or if the
     *     index exceeds the number of type arguments.
     */
    public static Type extractTypeArgument(Type t, int index) throws InvalidTypesException {
        if (t instanceof ParameterizedType) {
            Type[] actualTypeArguments = ((ParameterizedType) t).getActualTypeArguments();

            if (index < 0 || index >= actualTypeArguments.length) {
                throw new InvalidTypesException(
                        "Cannot extract the type argument with index "
                                + index
                                + " because the type has only "
                                + actualTypeArguments.length
                                + " type arguments.");
            } else {
                return actualTypeArguments[index];
            }
        } else {
            throw new InvalidTypesException(
                    "The given type " + t + " is not a parameterized type.");
        }
    }

    /**
     * Extracts a Single Abstract Method (SAM) as defined in Java Specification (4.3.2. The Class
     * Object, 9.8 Functional Interfaces, 9.4.3 Interface Method Body) from given class.
     *
     * @param baseClass a class that is a FunctionalInterface to retrieve a SAM from
     * @throws InvalidTypesException if the given class does not implement FunctionalInterface
     * @return single abstract method of the given class
     */
    public static Method getSingleAbstractMethod(Class<?> baseClass) {

        if (!baseClass.isInterface()) {
            throw new InvalidTypesException(
                    "Given class: " + baseClass + "is not a FunctionalInterface.");
        }

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Specify all generic type parameters explicitly on your function class or anonymous class.
  2. Use .returns(TypeInformation.of(new TypeHint<List<String>>(){})) to provide the type explicitly.
  3. Replace the lambda with an anonymous class that specifies concrete generics.
  4. Implement ResultTypeQueryable on your function to return the TypeInformation directly.

Example fix

// before
ds.map(x -> Arrays.asList(x.split(","))) // List without generic info
// after
ds.map(x -> Arrays.asList(x.split(",")))
  .returns(TypeInformation.of(new TypeHint<List<String>>(){}));
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(t instanceof ParameterizedType)) {
    throw new IllegalArgumentException(
        "Type must be parameterized; got raw type " + t);
}

Type guard

static boolean isParameterized(Type t) {
    return t instanceof ParameterizedType;
}

Prevention

When it happens

Trigger: The function's output type is a raw type (e.g. List.class instead of List<String>). A type variable (T) was not resolved through the type hierarchy. Lambda erasure causes the output type to be a raw Class with no parameterization.

Common situations: Using raw types instead of parameterized types (e.g. returning List instead of List<String>). Lambda functions where the compiler could not infer the generic type argument. Subclassing a Flink function interface without specifying the generic type parameters.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/385dbbbb2ddc0383. Report an issue: GitHub.