apache/flink · error · InvalidTypesException

Type Information could not be created.

Error message

Type Information could not be created.

What it means

The catch-all failure thrown at the end of `createTypeInfoWithTypeHierarchy` when the given `java.lang.reflect.Type` is none of: a Tuple subclass, a TypeVariable, a GenericArrayType, a ParameterizedType, or a plain Class. This is the 'I don't know what this type is' fallback — it means the Type object fell through every supported branch.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java:1019

                Class<?> componentClass = componentInfo.getTypeClass();
                Class<OUT> classArray =
                        (Class<OUT>)
                                (java.lang.reflect.Array.newInstance(componentClass, 0).getClass());

                return ObjectArrayTypeInfo.getInfoFor(classArray, componentInfo);
            }
        }
        // objects with generics are treated as Class first
        else if (t instanceof ParameterizedType) {
            return privateGetForClass(
                    typeToClass(t), typeHierarchy, (ParameterizedType) t, in1Type, in2Type);
        }
        // no tuple, no TypeVariable, no generic type
        else if (t instanceof Class) {
            return privateGetForClass((Class<OUT>) t, typeHierarchy);
        }

        throw new InvalidTypesException("Type Information could not be created.");
    }

    private <IN1, IN2> TypeInformation<?> createTypeInfoFromInputs(
            TypeVariable<?> returnTypeVar,
            List<Type> returnTypeHierarchy,
            TypeInformation<IN1> in1TypeInfo,
            TypeInformation<IN2> in2TypeInfo) {

        Type matReturnTypeVar = materializeTypeVariable(returnTypeHierarchy, returnTypeVar);

        // variable could be resolved
        if (!(matReturnTypeVar instanceof TypeVariable)) {
            return createTypeInfoWithTypeHierarchy(
                    returnTypeHierarchy, matReturnTypeVar, in1TypeInfo, in2TypeInfo);
        } else {
            returnTypeVar = (TypeVariable<?>) matReturnTypeVar;
        }

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Implement ResultTypeQueryable on the function and provide the TypeInformation explicitly
  2. Supply TypeInformation via `.returns(...)` on the DataStream operator
  3. Refactor the function to use concrete, supported types instead of exotic generics
  4. Use TypeInformation.of(...) or TypeHint to specify the type manually

Example fix

// before — exotic or unresolved type
dataStream.map(new MyWildcardFunction<? extends Number>())

// after — specify type explicitly
dataStream.map(new MyConcreteFunction())
          .returns(TypeInformation.of(MyEvent.class));
Defensive patterns

Strategy: fallback

Validate before calling

// Test type extraction before deploying
try {
    TypeInformation<?> info = TypeExtractor.createTypeInfo(MyFunction.class);
} catch (InvalidTypesException e) {
    System.err.println("Type extraction failed: " + e.getMessage()
        + " — provide TypeInformation explicitly");
}

Try / catch

try {
    resultStream = inputStream.map(myFunction);
} catch (InvalidTypesException e) {
    // Fall back to explicit type specification
    resultStream = inputStream.map(myFunction)
        .returns(TypeInformation.of(MyOutputType.class));
}

Prevention

When it happens

Trigger: The Type passed to the extractor is an exotic or unsupported java.lang.reflect.Type implementation (e.g. a WildcardType, a synthetic proxy type, or a custom Type implementation). Can also occur with types that represent none of the recognized categories in Java's reflection model.

Common situations: Using a function whose type involves wildcard captures (`? extends Number`). Passing a dynamically proxied or bytecode-generated class as a function. Extremely unusual generics involving intersection types or synthetic bridge methods.

Related errors


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