apache/flink · error · InvalidTypesException

Could not extract type information.

Error message

Could not extract type information.

What it means

Thrown by TypeExtractor.createTypeInfo(Type) when privateCreateTypeInfo returns null, meaning the type extraction logic could not determine any TypeInformation for the given Type. This is a terminal failure: after traversing factories, tuple handling, POJO analysis, enum handling, and all other type categories, nothing matched.

Source

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

            } else {
                throw e;
            }
        }
    }

    // --------------------------------------------------------------------------------------------
    //  Create type information
    // --------------------------------------------------------------------------------------------

    @SuppressWarnings("unchecked")
    public static <T> TypeInformation<T> createTypeInfo(Class<T> type) {
        return (TypeInformation<T>) createTypeInfo((Type) type);
    }

    public static TypeInformation<?> createTypeInfo(Type t) {
        TypeInformation<?> ti = new TypeExtractor().privateCreateTypeInfo(t);
        if (ti == null) {
            throw new InvalidTypesException("Could not extract type information.");
        }
        return ti;
    }

    /**
     * Creates a {@link TypeInformation} from the given parameters.
     *
     * <p>If the given {@code instance} implements {@link ResultTypeQueryable}, its information is
     * used to determine the type information. Otherwise, the type information is derived based on
     * the given class information.
     *
     * @param instance instance to determine type information for
     * @param baseClass base class of {@code instance}
     * @param clazz class of {@code instance}
     * @param returnParamPos index of the return type in the type arguments of {@code clazz}
     * @param <OUT> output type
     * @return type information
     */

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Register a TypeInfoFactory for the custom type using TypeExtractor.registerFactory().
  2. Ensure the type is a concrete class with accessible fields (POJO) or use a Tuple.
  3. Provide TypeInformation explicitly via TypeInformation.of(new TypeHint<...>(){}).
  4. If the type is an interface, use a concrete implementation class instead.
  5. Implement ResultTypeQueryable if the type is used as a function output.

Example fix

// before
TypeInformation<?> ti = TypeExtractor.createTypeInfo(MyInterface.class);
// after
TypeExtractor.registerFactory(MyType.class, MyTypeInfoFactory.class);
TypeInformation<?> ti = TypeExtractor.createTypeInfo(MyType.class);
Defensive patterns

Strategy: validation

Validate before calling

TypeInformation<?> ti = new TypeExtractor().privateCreateTypeInfo(t);
if (ti == null) {
    throw new IllegalArgumentException(
        "Flink cannot extract TypeInformation for " + t
        + "; register a TypeInfoFactory or provide it explicitly");
}

Type guard

static boolean isExtractableType(Class<?> clazz) {
    return clazz.isPrimitive() || clazz.isEnum()
        || Tuple.class.isAssignableFrom(clazz)
        || clazz.isAssignableFrom(String.class)
        || hasNoArgConstructor(clazz);
}

Try / catch

try {
    TypeInformation<?> ti = TypeExtractor.createTypeInfo(type);
} catch (InvalidTypesException e) {
    // register a factory or provide explicit type info
    TypeInformation<?> ti = TypeInformation.of(new TypeHint<MyType>(){});
}

Prevention

When it happens

Trigger: Calling TypeExtractor.createTypeInfo(SomeUnknownType.class) where the type doesn't fit any known category. The type is an interface with no concrete implementation hints. The type is void.class or Void.class. The type is a synthetic or proxy class that Flink cannot analyze.

Common situations: Trying to use an interface or abstract class as a data type without providing TypeInformation. Using Java types that Flink doesn't support natively (e.g. raw Object, or a type that is neither a POJO, Tuple, primitive, nor Avro). Missing TypeInfoFactory for a custom type.

Related errors


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