ReactiveX/RxJava · error · IllegalArgumentException
Overflow! start + count is bigger than Long.MAX_VALUE
Error message
Overflow! start + count is bigger than Long.MAX_VALUE
What it means
Thrown by Streamable.intervalRange (scheduler overload) when start + (count - 1) overflows Long.MAX_VALUE. The library computes the inclusive end and detects wraparound (positive start yielding a negative end), failing fast rather than emitting a corrupted sequence.
Source
Thrown at src/main/java/io/reactivex/rxjava4/core/Streamable.java:410
* @param initialDelay the time to delay before the {@code start} item is emitted
* @param period the period of how often emit the next item
* @param unit the time unit for both {@code initialDelay} and {@code period}
* @param scheduler the scheduler to use for the timed waiting
* @return the new {@code Streamable} instance
* @throws NullPointerException if {@code unit} or {@code scheduler} is {@code null}
* @throws IllegalArgumentException if {@code count} is negative
*/
static Streamable<Long> intervalRange(long start, long count,
long initialDelay, long period, TimeUnit unit, Scheduler scheduler) {
Objects.requireNonNull(unit, "unit is null");
Objects.requireNonNull(scheduler, "scheduler is null");
if (count < 0) {
throw new IllegalArgumentException("count >= 0 required but it was " + count);
}
long end = start + (count - 1);
if (start > 0 && end < 0) {
throw new IllegalArgumentException("Overflow! start + count is bigger than Long.MAX_VALUE");
}
return RxJavaPlugins.onAssembly(new StreamableIntervalRange(start, count, initialDelay, period, unit, scheduler, null));
}
/**
* Constructs a {@code Streamable} that after the initial delay, starts emitting an ever increasing
* numbers from {@code start} up to {@code start + count} exclusive with the given period.
* <p>
* If the provided {@link ExecutorService} is a {@link ScheduledExecutorService}, its
* {@link ScheduledExecutorService#scheduleAtFixedRate(Runnable, long, long, TimeUnit)} will be used.
* Otherwise, a plain {@code ExecutorService} will be wrapped via {@link Schedulers#from(Executor)}.
* <p>
* If there are processing delays, this source may emit multiple queued up items in a quick succession.
* @param start the first long value to emit
* @param count the number of items to emit, use {@link Long#MAX_VALUE} for an unlimited range
* @param initialDelay the time to delay before the {@code start} item is emitted
* @param period the period of how often emit the next itmeView on GitHub (pinned to a8ab535614)
Solutions
- Reduce start and/or count so the inclusive end stays <= Long.MAX_VALUE.
- Validate up front: boolean overflow = start > 0L && Long.MAX_VALUE - (count - 1) < start.
- Page the emission into smaller chunks.
Example fix
// before long start = Long.MAX_VALUE - 5; Streamable.intervalRange(start, 50L, 0, 1, TimeUnit.SECONDS, scheduler); // after long start = Long.MAX_VALUE - 5; long count = Math.min(50L, Long.MAX_VALUE - start + 1); Streamable.intervalRange(start, count, 0, 1, TimeUnit.SECONDS, scheduler);
Defensive patterns
Strategy: validation
Validate before calling
long end = start + (count - 1);
boolean overflow = start > 0L && end < 0L;
if (overflow) {
count = Long.MAX_VALUE - start + 1;
} Try / catch
try {
return Streamable.intervalRange(start, count, initialDelay, period, unit, scheduler);
} catch (IllegalArgumentException e) {
return Streamable.empty();
} Prevention
- Bound start away from Long.MAX_VALUE when count is large.
- Apply the wraparound check before calling.
- Page large ranges into smaller chunks.
When it happens
Trigger: Calling Streamable.intervalRange(start, count, initialDelay, period, unit, scheduler) with start > 0L and an inclusive end exceeding Long.MAX_VALUE.
Common situations: Sequences seeded near Long.MAX_VALUE; computed ranges never bounded; ID/counter ranges at the top of the long domain.
Related errors
- Overflow! start + count is bigger than Long.MAX_VALUE
- Overflow! start + count is bigger than Long.MAX_VALUE
- count >= 0 required but it was {}
- Integer overflow
- count >= 0 required but it was {}
AI-assisted analysis of ReactiveX/RxJava@a8ab535614 (2026-08-13).
Data as JSON: /api/errors/5bad813576e7c475.
Report an issue: GitHub.