{"record":{"id":"7c333b3589bfde14","repo":"apache/flink","slug":"collection-must-not-contain-null-elements","errorCode":null,"errorMessage":"Collection must not contain null elements","messagePattern":"Collection must not contain null elements","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentImpl.java","lineNumber":236,"sourceCode":"    }\n\n    public CheckpointConfig getCheckpointCfg() {\n        return checkpointCfg;\n    }\n\n    // -----------------------------------------------\n    //              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(","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentImpl.java#L218-L254","documentation":"Thrown by extractTypeInfoFromCollection when the first element of the collection passed to fromCollection is null. Type extraction reflects on the first element's class; a null element gives it nothing to inspect, so it fails fast with IllegalArgumentException.","triggerScenarios":"env.fromCollection(Arrays.asList(null, event1, event2)) — any collection whose first element (data.iterator().next()) is null. Note: only the FIRST element matters; nulls later in the collection do not trigger this check here.","commonSituations":"Arrays.asList(null, ...) patterns, lists built with add(null) placeholders, or map/filter chains upstream of submission that produce a null head element.","solutions":["Filter nulls before submission: data.stream().filter(Objects::nonNull).collect(toList())","Fix the producer of the collection so it never inserts null placeholders","Use fromCollection(data, explicitTypeInformation) so extraction does not depend on the first element"],"exampleFix":"// before\nenv.fromCollection(Arrays.asList(null, \"a\", \"b\"));\n\n// after\nList<String> clean = Arrays.asList(null, \"a\", \"b\").stream()\n        .filter(Objects::nonNull)\n        .collect(Collectors.toList());\nenv.fromCollection(clean);","handlingStrategy":"validation","validationCode":"List<OUT> clean = data.stream().filter(Objects::nonNull).collect(Collectors.toList());\nif (clean.isEmpty()) throw new IllegalArgumentException(\"no non-null elements\");\nenv.fromCollection(clean);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Sanitize collections with Objects::nonNull before submission","Add Objects.requireNonNull at the producer so nulls never reach job assembly"],"tags":["datastream-v2","type-extraction","null-safety"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}