{"record":{"id":"064b142c00db9d87","repo":"apache/flink","slug":"automatic-type-extraction-is-not-possible-on-candi","errorCode":null,"errorMessage":"Automatic type extraction is not possible on candidates with null values. Please specify the types directly.","messagePattern":"Automatic type extraction is not possible on candidates with null values\\. Please specify the types directly\\.","errorType":"validation","errorClass":"InvalidTypesException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java","lineNumber":2385,"sourceCode":"        if (value instanceof Tuple) {\n            Tuple t = (Tuple) value;\n            int numFields = t.getArity();\n            if (numFields != countFieldsInClass(value.getClass())) {\n                // not a tuple since it has more fields.\n                return analyzePojo(\n                        value.getClass(),\n                        new ArrayList<>(),\n                        null,\n                        null); // we immediately call analyze Pojo here, because\n                // there is currently no other type that can handle such a class.\n            }\n\n            TypeInformation<?>[] infos = new TypeInformation[numFields];\n            for (int i = 0; i < numFields; i++) {\n                Object field = t.getField(i);\n\n                if (field == null) {\n                    throw new InvalidTypesException(\n                            \"Automatic type extraction is not possible on candidates with null values. \"\n                                    + \"Please specify the types directly.\");\n                }\n\n                infos[i] = privateGetForObject(field);\n            }\n            return new TupleTypeInfo(value.getClass(), infos);\n        } else if (value instanceof Row) {\n            Row row = (Row) value;\n            int arity = row.getArity();\n            for (int i = 0; i < arity; i++) {\n                if (row.getField(i) == null) {\n                    LOG.warn(\n                            \"Cannot extract type of Row field, because of Row field[\"\n                                    + i\n                                    + \"] is null. \"\n                                    + \"Should define RowTypeInfo explicitly.\");\n                    return privateGetForClass((Class<X>) value.getClass(), new ArrayList<>());","sourceCodeStart":2367,"sourceCodeEnd":2403,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java#L2367-L2403","documentation":"Thrown by TypeExtractor.privateGetForObject when extracting type information from a Tuple instance at runtime and one of the tuple's fields is null. Flink's automatic type extraction infers types from runtime values, and a null field provides no type information, making extraction impossible.","triggerScenarios":"Called during privateGetForObject when value is a Tuple and one of t.getField(i) returns null. This occurs when TypeExtractor.getForObject(tuple) is called on a Tuple where at least one field is null, preventing the extractor from inferring that field's TypeInformation from the runtime value.","commonSituations":"Creating Tuple instances with null fields and passing them to operations that trigger automatic type extraction (e.g., fromCollection, fromElements without explicit TypeInformation). Returning a Tuple with a null field from a UDF during the initial type inference pass. Testing with sample data that contains null tuple fields.","solutions":["Provide explicit TypeInformation to avoid runtime inference: e.g., fromCollection(data, TypeInformation.of(new TypeHint<Tuple2<String,Integer>>(){})).","Ensure sample/seed data used for type inference has no null tuple fields; use placeholder non-null values instead.","Use .returns() with a TypeHint on the operation to bypass value-based inference.","For nullable fields, use a POJO or Row type with explicit TypeInformation instead of Tuple."],"exampleFix":"// before\nTuple2<String, Integer> t = new Tuple2<>(\"hello\", null);\nDataSet<Tuple2<String,Integer>> ds = env.fromElements(t);\n// throws: null value prevents type extraction\n\n// after\nDataSet<Tuple2<String,Integer>> ds =\n    env.fromElements(new Tuple2<>(\"hello\", 0))\n       .returns(TypeInformation.of(new TypeHint<Tuple2<String,Integer>>(){}));","handlingStrategy":"validation","validationCode":"// Before extracting type from a Tuple object, check for null fields\nif (value instanceof Tuple) {\n    Tuple t = (Tuple) value;\n    for (int i = 0; i < t.getArity(); i++) {\n        if (t.getField(i) == null) {\n        // provide explicit TypeInformation instead of relying on runtime inference\n        }\n    }\n}","typeGuard":"static boolean tupleHasNoNulls(Object value) {\n    if (!(value instanceof Tuple)) return true;\n    Tuple t = (Tuple) value;\n    for (int i = 0; i < t.getArity(); i++) {\n        if (t.getField(i) == null) return false;\n    }\n    return true;\n}","tryCatchPattern":"try {\n    TypeInformation<?> ti = TypeExtractor.getForObject(tupleValue);\n} catch (InvalidTypesException e) {\n    ti = TypeInformation.of(new TypeHint<Tuple2<String, Integer>>(){});\n}","preventionTips":["Never pass Tuple instances with null fields to operations that trigger automatic type extraction.","Use non-null placeholder values in sample/seed data.","Provide explicit TypeInformation via fromCollection(data, typeInfo) or .returns(TypeHint)."],"tags":["type-extraction","tuple","null-values","runtime-inference"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}