{"record":{"id":"e999db84427c9904","repo":"apache/flink","slug":"collection-must-not-be-empty","errorCode":null,"errorMessage":"Collection must not be empty","messagePattern":"Collection must not be empty","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentImpl.java","lineNumber":231,"sourceCode":"        return transformations;\n    }\n\n    public void setParallelism(int parallelism) {\n        executionConfig.setParallelism(parallelism);\n    }\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        }","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentImpl.java#L213-L249","documentation":"Thrown by ExecutionEnvironmentImpl.extractTypeInfoFromCollection when fromCollection(Collection) is called with an empty collection. Flink derives the element TypeInformation by reflecting on the first element, so with zero elements it has nothing to infer from and rejects the call with IllegalArgumentException.","triggerScenarios":"Calling env.fromCollection(Collections.emptyList()) or env.fromCollection(new ArrayList<>()) on a DataStream v2 ExecutionEnvironment without passing an explicit TypeInformation.","commonSituations":"Empty lists produced by filtering a source dataset before submission, parameterized test runs with no fixtures, or dynamic data sets that happen to be empty at job-assembly time.","solutions":["Pass a non-empty collection, or guard the call site: if (data.isEmpty()) return; before fromCollection","Use the overload fromCollection(data, TypeInformation.of(...)) / with an explicit TypeInformation if your pipeline must tolerate empty inputs","Unit-test job assembly with representative (non-empty) sample data"],"exampleFix":"// before\nenv.fromCollection(new ArrayList<Event>());\n\n// after\nif (!events.isEmpty()) {\n    env.fromCollection(events);\n} else {\n    env.fromCollection(events, TypeInformation.of(Event.class)); // explicit type, empty ok only if API allows; otherwise skip\n}","handlingStrategy":"validation","validationCode":"if (data == null || data.isEmpty()) {\n    throw new IllegalArgumentException(\"input collection is empty; cannot build source\");\n}\nenv.fromCollection(data);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call fromCollection with a possibly-empty collection; assert non-empty at the boundary","Prefer fromCollection(data, TypeInformation) when input size is unpredictable"],"tags":["datastream-v2","type-extraction","validation"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}