apache/flink · error · UnsupportedOperationException

Generic types have been disabled in the ExecutionConfig and

Error message

Generic types have been disabled in the ExecutionConfig and type {} is treated as a generic type.

What it means

Thrown by GenericTypeInfo.createSerializer() when ExecutionConfig has disabled generic types (hasGenericTypesDisabled() == true) but the type in question is a generic type (i.e. only Kryo could serialize it). Disabling generic types is an explicit opt-in safety feature that forces users to provide proper POJO/Avro type info; hitting this error means a type fell through to the generic/Kryo fallback that the user forbade.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/GenericTypeInfo.java:86

    }

    @Override
    @PublicEvolving
    public Class<T> getTypeClass() {
        return typeClass;
    }

    @Override
    @PublicEvolving
    public boolean isKeyType() {
        return Comparable.class.isAssignableFrom(typeClass);
    }

    @Override
    @PublicEvolving
    public TypeSerializer<T> createSerializer(SerializerConfig config) {
        if (config.hasGenericTypesDisabled()) {
            throw new UnsupportedOperationException(
                    "Generic types have been disabled in the ExecutionConfig and type "
                            + this.typeClass.getName()
                            + " is treated as a generic type.");
        }

        return new KryoSerializer<T>(this.typeClass, config);
    }

    @SuppressWarnings("unchecked")
    @Override
    @PublicEvolving
    public TypeComparator<T> createComparator(
            boolean sortOrderAscending, ExecutionConfig executionConfig) {
        if (isKeyType()) {
            @SuppressWarnings("rawtypes")
            GenericTypeComparator comparator =
                    new GenericTypeComparator(
                            sortOrderAscending,

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Make the offending class a proper POJO (public, no-arg constructor, public getters/setters) so Flink uses PojoTypeInfo instead of GenericTypeInfo.
  2. Register an explicit TypeInformation / TypeSerializer for the class via .registerTypeWithKryoSerializer or a TypeInfoFactory.
  3. If Kryo is acceptable, re-enable generic types: executionConfig.enableGenericTypes().
  4. Switch to a Tuple, Row, or Avro type that Flink understands natively.

Example fix

// before
env.getConfig().disableGenericTypes();
env.fromElements(new MyType()); // MyType not a valid POJO -> GenericTypeInfo -> throw

// after: make MyType a proper POJO
public class MyType {
  public MyType() {}
  private int v; public int getV(){return v;} public void setV(int v){this.v=v;}
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate type is a POJO before disabling generics
if (TypeInformation.of(MyType.class) instanceof GenericTypeInfo) {
    throw new IllegalStateException("MyType is generic; make it a POJO before disableGenericTypes()");
}

Type guard

static boolean isPojo(Class<?> c) {
    return TypeInformation.of(c) instanceof org.apache.flink.api.java.typeutils.PojoTypeInfo;
}

Prevention

When it happens

Trigger: Calling executionConfig.disableGenericTypes() (or the equivalent) and then having TypeExtractor produce a GenericTypeInfo for some type in the job, which triggers createSerializer().

Common situations: A team enables 'no generics' to enforce type safety, then introduces a type Flink cannot treat as a POJO (missing getter/setter, non-public class, nested generics) so it degrades to generic and the serializer creation fails at runtime.

Related errors


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