{"record":{"id":"2d2bccebe84a778c","repo":"apache/flink","slug":"enumtypeinfo-can-only-be-used-for-subclasses-of-ja","errorCode":null,"errorMessage":"EnumTypeInfo can only be used for subclasses of java.lang.Enum","messagePattern":"EnumTypeInfo can only be used for subclasses of java\\.lang\\.Enum","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/EnumTypeInfo.java","lineNumber":51,"sourceCode":"\n/**\n * A {@link TypeInformation} for java enumeration types.\n *\n * @param <T> The type represented by this type information.\n */\n@Public\npublic class EnumTypeInfo<T extends Enum<T>> extends TypeInformation<T> implements AtomicType<T> {\n\n    private static final long serialVersionUID = 8936740290137178660L;\n\n    private final Class<T> typeClass;\n\n    @PublicEvolving\n    public EnumTypeInfo(Class<T> typeClass) {\n        checkNotNull(typeClass, \"Enum type class must not be null.\");\n\n        if (!Enum.class.isAssignableFrom(typeClass)) {\n            throw new IllegalArgumentException(\n                    \"EnumTypeInfo can only be used for subclasses of \" + Enum.class.getName());\n        }\n\n        this.typeClass = typeClass;\n    }\n\n    @Override\n    @PublicEvolving\n    public TypeComparator<T> createComparator(\n            boolean sortOrderAscending, ExecutionConfig executionConfig) {\n        return new EnumComparator<T>(sortOrderAscending);\n    }\n\n    @Override\n    @PublicEvolving\n    public boolean isBasicType() {\n        return false;\n    }","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/EnumTypeInfo.java#L33-L69","documentation":"Thrown by the EnumTypeInfo constructor when the supplied class is not a subclass of java.lang.Enum. EnumTypeInfo is a specialized, schema-free type information valid only for Java enums; passing any other class is a programming error caught by an Enum.class.isAssignableFrom check.","triggerScenarios":"Explicitly constructing new EnumTypeInfo<>(SomeClass.class) where SomeClass is not an enum; a generic factory incorrectly routing a non-enum class to EnumTypeInfo.","commonSituations":"Hand-rolling TypeInformation for a class that merely looks enum-like (constants in a class); copy-paste of EnumTypeInfo construction for a non-enum type; misuse of the type system API.","solutions":["Only construct EnumTypeInfo with a Class<? extends Enum>.","Let TypeExtractor infer type information automatically rather than constructing EnumTypeInfo by hand.","For non-enum classes use PojoTypeInfo / GenericTypeInfo / a custom TypeInformation instead."],"exampleFix":"// before\nnew EnumTypeInfo<>(MyConstantsClass.class); // not an enum\n\n// after (if it really is an enum)\npublic enum MyEnum { A, B; }\nnew EnumTypeInfo<>(MyEnum.class);\n// or, for a non-enum class, let TypeExtractor handle it:\nTypeInformation.of(MyConstantsClass.class);","handlingStrategy":"type-guard","validationCode":"if (!Enum.class.isAssignableFrom(typeClass)) {\n    throw new IllegalArgumentException(\"EnumTypeInfo requires a java.lang.Enum subclass: \" + typeClass);\n}","typeGuard":"static boolean isEnumType(Class<?> c) {\n    return c != null && Enum.class.isAssignableFrom(c);\n}","tryCatchPattern":null,"preventionTips":["Prefer TypeInformation.of(clazz) over manually constructing EnumTypeInfo.","Only pass enum classes to EnumTypeInfo.","Unit-test type info construction for custom classes."],"tags":["type-info","enum","validation"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}