{"record":{"id":"1d4eb34969542d48","repo":"apache/flink","slug":"could-not-create-typeinformation-for-type-type","errorCode":null,"errorMessage":"Could not create TypeInformation for type {type}; please specify the TypeInformation manually via the version of the method that explicitly accepts it as an argument.","messagePattern":"Could not create TypeInformation for type (.+?); please specify the TypeInformation manually via the version of the method that explicitly accepts it as an argument\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentImpl.java","lineNumber":243,"sourceCode":"    //              Internal Methods\n    // -----------------------------------------------\n\n    private static <OUT> TypeInformation<OUT> extractTypeInfoFromCollection(Collection<OUT> data) {\n        Preconditions.checkNotNull(data, \"Collection must not be null\");\n        if (data.isEmpty()) {\n            throw new IllegalArgumentException(\"Collection must not be empty\");\n        }\n\n        OUT first = data.iterator().next();\n        if (first == null) {\n            throw new IllegalArgumentException(\"Collection must not contain null elements\");\n        }\n\n        TypeInformation<OUT> typeInfo;\n        try {\n            typeInfo = TypeExtractor.getForObject(first);\n        } catch (Exception e) {\n            throw new RuntimeException(\n                    \"Could not create TypeInformation for type \"\n                            + first.getClass()\n                            + \"; please specify the TypeInformation manually via the version of the \"\n                            + \"method that explicitly accepts it as an argument.\",\n                    e);\n        }\n        return typeInfo;\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    private static <OUT, T extends TypeInformation<OUT>> T getSourceTypeInfo(\n            org.apache.flink.api.connector.source.Source<OUT, ?, ?> source, String sourceName) {\n        TypeInformation<OUT> resolvedTypeInfo = null;\n        if (source instanceof ResultTypeQueryable) {\n            resolvedTypeInfo = ((ResultTypeQueryable<OUT>) source).getProducedType();\n        }\n        if (resolvedTypeInfo == null) {\n            try {","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentImpl.java#L225-L261","documentation":"Wrapped RuntimeException thrown when TypeExtractor.getForObject(firstElement) fails while inferring the element type for fromCollection. This happens when the first element's class is too complex or generic for reflection-based extraction (e.g. raw generic containers, anonymous classes, tuples with generic fields).","triggerScenarios":"env.fromCollection(List.of(new Tuple2<String, Long>(...)-like generic holder)) where the element's generic parameter types cannot be recovered by TypeExtractor; elements of anonymous or local classes with non-resolvable generics.","commonSituations":"Custom POJO wrappers around generics (e.g. Result<T>), Scala/Java interop collections, or elements whose fields use unresolvable type variables. The thrown cause (checked exceptions from TypeExtractor) is attached as the cause.","solutions":["Call the fromCollection overload that takes an explicit TypeInformation (e.g. TypeInformation.of(MyClass.class) or a custom TypeInfoFactory)","Annotate the element class with @TypeInfo(MyClassTypeInfoFactory.class) so getForObject succeeds","Inspect the cause chain of the RuntimeException to see exactly which field/type failed extraction"],"exampleFix":"// before\nenv.fromCollection(results); // Result<T> too generic for extraction\n\n// after\nenv.fromCollection(results, TypeInformation.of(new TypeHint<Result<String>>() {}));","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    env.fromCollection(data);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Could not create TypeInformation\")) {\n        env.fromCollection(data, TypeInformation.of(elementClass));\n    } else { throw e; }\n}","preventionTips":["Default to the explicit-TypeInformation overload for custom/generic element types","Use @TypeInfo + TypeInfoFactory on complex POJOs"],"tags":["datastream-v2","type-extraction","generics"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}