apache/flink · error · IllegalArgumentException
Collection must not be empty
Error message
Collection must not be empty
What it means
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.
Source
Thrown at flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentImpl.java:231
return transformations;
}
public void setParallelism(int parallelism) {
executionConfig.setParallelism(parallelism);
}
public CheckpointConfig getCheckpointCfg() {
return checkpointCfg;
}
// -----------------------------------------------
// Internal Methods
// -----------------------------------------------
private static <OUT> TypeInformation<OUT> extractTypeInfoFromCollection(Collection<OUT> data) {
Preconditions.checkNotNull(data, "Collection must not be null");
if (data.isEmpty()) {
throw new IllegalArgumentException("Collection must not be empty");
}
OUT first = data.iterator().next();
if (first == null) {
throw new IllegalArgumentException("Collection must not contain null elements");
}
TypeInformation<OUT> typeInfo;
try {
typeInfo = TypeExtractor.getForObject(first);
} catch (Exception e) {
throw new RuntimeException(
"Could not create TypeInformation for type "
+ first.getClass()
+ "; please specify the TypeInformation manually via the version of the "
+ "method that explicitly accepts it as an argument.",
e);
}View on GitHub (pinned to 2f3c205e92)
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
Example fix
// before
env.fromCollection(new ArrayList<Event>());
// after
if (!events.isEmpty()) {
env.fromCollection(events);
} else {
env.fromCollection(events, TypeInformation.of(Event.class)); // explicit type, empty ok only if API allows; otherwise skip
} Defensive patterns
Strategy: validation
Validate before calling
if (data == null || data.isEmpty()) {
throw new IllegalArgumentException("input collection is empty; cannot build source");
}
env.fromCollection(data); Prevention
- Never call fromCollection with a possibly-empty collection; assert non-empty at the boundary
- Prefer fromCollection(data, TypeInformation) when input size is unpredictable
When it happens
Trigger: Calling env.fromCollection(Collections.emptyList()) or env.fromCollection(new ArrayList<>()) on a DataStream v2 ExecutionEnvironment without passing an explicit TypeInformation.
Common situations: 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.
Related errors
- The given class is no subclass of {Writable.class.getName()}
- Unknown Error. Type is null.
- Unknown Error. TypeInformation is null.
- Collection must not contain null elements
- Could not create TypeInformation for type {type}; please spe
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/e999db84427c9904.
Report an issue: GitHub.