apache/flink · error · IllegalArgumentException
The 'to' value must not be smaller than the 'from' value.
Error message
The 'to' value must not be smaller than the 'from' value.
What it means
NumberSequenceIterator(from, to) emits the inclusive range [from, to] and refuses from > to with IllegalArgumentException. It backs env.generateSequence(from, to) and other sequence sources. The guard catches inverted bounds before any split/iteration happens.
Source
Thrown at flink-core/src/main/java/org/apache/flink/util/NumberSequenceIterator.java:50
private static final long serialVersionUID = 1L;
/** The last number returned by the iterator. */
private final long to;
/** The next number to be returned. */
private long current;
/**
* Creates a new splittable iterator, returning the range [from, to]. Both boundaries of the
* interval are inclusive.
*
* @param from The first number returned by the iterator.
* @param to The last number returned by the iterator.
*/
public NumberSequenceIterator(long from, long to) {
if (from > to) {
throw new IllegalArgumentException(
"The 'to' value must not be smaller than the 'from' value.");
}
this.current = from;
this.to = to;
}
/**
* Internal constructor to allow for empty iterators.
*
* @param from The first number returned by the iterator.
* @param to The last number returned by the iterator.
* @param unused A dummy parameter to disambiguate the constructor.
*/
private NumberSequenceIterator(long from, long to, boolean unused) {
this.current = from;
this.to = to;
}View on GitHub (pinned to 2f3c205e92)
Solutions
- Fix the argument order so from <= to.
- If bounds come from config, validate/normalize (min/max) before constructing.
- For an intentionally empty source, use 0 elements (e.g. from=1, to=0 is invalid too — skip creating the source instead).
Example fix
// before NumberSequenceIterator it = new NumberSequenceIterator(end, start); // swapped // after NumberSequenceIterator it = new NumberSequenceIterator(start, end);
Defensive patterns
Strategy: validation
Validate before calling
Preconditions.checkArgument(from <= to, "from (%s) must be <= to (%s)", from, to); NumberSequenceIterator it = new NumberSequenceIterator(from, to);
Prevention
- Name bounds explicitly (lower/upper) to avoid swapped arguments.
- Validate user-supplied bounds before building sources.
When it happens
Trigger: new NumberSequenceIterator(10, 1); env.generateSequence(end, start) with swapped variables; from/to derived from config where the lower bound defaulted higher than the upper.
Common situations: Swapped constructor arguments; generated source parameters where 'from' exceeds 'to'; refactoring renaming bounds and inverting their assignment.
Related errors
- The number of partitions must be at least 1.
- The output size cannot be smaller than zero.
- The output cardinality cannot be smaller than zero.
- The size of produced records must be positive.
- The filter factor cannot be smaller than zero.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/cef9fa110dbd4325.
Report an issue: GitHub.