apache/flink · error · FlinkRuntimeException

The TypeHint is using a generic variable.This is not support

Error message

The TypeHint is using a generic variable.This is not supported, generic types must be fully specified for the TypeHint.

What it means

TypeHint<T> captures its generic argument by analyzing the anonymous subclass's superclass signature. If T is itself an unresolved type variable (e.g., new TypeHint<T>(){} inside a generic method where T is not pinned), TypeExtractor.createTypeInfo throws InvalidTypesException, which TypeHint wraps as a FlinkRuntimeException. A TypeHint must be created with fully specified, concrete type arguments.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/common/typeinfo/TypeHint.java:52

 *
 * <pre>{@code
 * TypeInformation<Tuple2<String, Long>> info = new TypeHint<Tuple2<String, Long>>(){}.getTypeInfo();
 * }</pre>
 *
 * @param <T> The type information to hint.
 */
@Public
public abstract class TypeHint<T> {

    /** The type information described by the hint. */
    private final TypeInformation<T> typeInfo;

    /** Creates a hint for the generic type in the class signature. */
    public TypeHint() {
        try {
            this.typeInfo = TypeExtractor.createTypeInfo(this, TypeHint.class, getClass(), 0);
        } catch (InvalidTypesException e) {
            throw new FlinkRuntimeException(
                    "The TypeHint is using a generic variable."
                            + "This is not supported, generic types must be fully specified for the TypeHint.");
        }
    }

    // ------------------------------------------------------------------------

    /**
     * Gets the type information described by this TypeHint.
     *
     * @return The type information described by this TypeHint.
     */
    public TypeInformation<T> getTypeInfo() {
        return typeInfo;
    }

    // ------------------------------------------------------------------------

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Make the TypeHint concrete at the call site: new TypeHint<Tuple2<String,String>>(){} with fully specified arguments, not a type variable.
  2. If you need TypeInformation for a generic method's T, require the caller to pass a TypeHint<T> rather than constructing one internally.
  3. Use TypeInformation.of(TypeHint) at a concrete call site instead of a generic helper.

Example fix

// before
public <T> TypeInformation<T> info() {
    return TypeInformation.of(new TypeHint<T>(){}); // throws: T unresolved
}

// after
public <T> TypeInformation<T> info(TypeHint<T> hint) {
    return TypeInformation.of(hint);
}
// caller: info(new TypeHint<Tuple2<String,String>>(){});
Defensive patterns

Strategy: type-guard

Validate before calling

// Ensure the TypeHint is created at a concrete call site, not with a type variable
// If building inside a generic method, require the caller to pass the TypeHint
public <T> void use(TypeHint<T> hint) {
    TypeInformation<T> ti = TypeInformation.of(hint);
}

Type guard

// Compile-time: a TypeHint with an unresolved type variable cannot be constructed correctly.
// Enforce by only accepting TypeHint from concrete call sites.
static boolean isConcreteHint(TypeHint<?> hint) {
    try {
        hint.getTypeInfo();
        return true;
    } catch (FlinkRuntimeException e) {
        return false;
    }
}

Try / catch

// Not recommended to catch; fix the TypeHint to be concrete.
// If wrapping dynamic type code:
try {
    ti = TypeInformation.of(new TypeHint<T>(){});
} catch (FlinkRuntimeException e) {
    throw new IllegalArgumentException(
        "TypeHint must be created with concrete type arguments at the call site", e);
}

Prevention

When it happens

Trigger: Writing new TypeHint<T>(){} inside a generic method/class where T is still a type variable; building TypeHints dynamically from generic methods that do not fix T; refactor that moved a TypeHint into a generic helper without specializing it.

Common situations: Generic utility methods that try to build TypeInformation for a type parameter T; copy-pasting a TypeHint example into generic code; libraries that accept Class<T> and attempt TypeHint<T> internally.

Related errors


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