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 Observable.intervalRange when start + (count - 1) overflows Long.MAX_VALUE. The library detects wraparound (positive start producing a negative inclusive end) and fails fast rather than emitting a corrupted sequence.

Source

Thrown at src/main/java/io/reactivex/rxjava4/core/Observable.java:2099

     * @throws IllegalArgumentException
     *             if {@code count} is negative, or if {@code start} + {@code count} − 1 exceeds
     *             {@link Long#MAX_VALUE}
     */
    @CheckReturnValue
    @NonNull
    @SchedulerSupport(SchedulerSupport.CUSTOM)
    public static Observable<Long> intervalRange(long start, long count, long initialDelay, long period, @NonNull TimeUnit unit, @NonNull Scheduler scheduler) {
        if (count < 0) {
            throw new IllegalArgumentException("count >= 0 required but it was " + count);
        }

        if (count == 0L) {
            return Observable.<Long>empty().delay(initialDelay, unit, scheduler);
        }

        long end = start + (count - 1);
        if (start > 0 && end < 0) {
            throw new IllegalArgumentException("Overflow! start + count is bigger than Long.MAX_VALUE");
        }
        Objects.requireNonNull(unit, "unit is null");
        Objects.requireNonNull(scheduler, "scheduler is null");

        return RxJavaPlugins.onAssembly(new ObservableIntervalRange(start, end, Math.max(0L, initialDelay), Math.max(0L, period), unit, scheduler));
    }

    /**
     * Returns an {@code Observable} that signals the given (constant reference) item and then completes.
     * <p>
     * <img width="640" height="290" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/just.item.png" alt="">
     * <p>
     * Note that the item is taken and re-emitted as is and not computed by any means by {@code just}. Use {@link #fromCallable(Callable)}
     * to generate a single item on demand (when {@link Observer}s subscribe to it).
     * <p>
     * See the multi-parameter overloads of {@code just} to emit more than one (constant reference) items one after the other.
     * Use {@link #fromArray(Object...)} to emit an arbitrary number of items that are known upfront.
     * <p>

View on GitHub (pinned to a8ab535614)

Solutions

  1. Reduce start and/or count so the inclusive end stays <= Long.MAX_VALUE.
  2. Validate up front: boolean overflow = start > 0L && Long.MAX_VALUE - (count - 1) < start.
  3. Page the emission into smaller chunks if you need that magnitude.

Example fix

// before
long start = Long.MAX_VALUE - 5;
Observable.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);
Observable.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 Observable.intervalRange(start, count, initialDelay, period, unit, scheduler);
} catch (IllegalArgumentException e) {
    return Observable.empty();
}

Prevention

When it happens

Trigger: Calling Observable.intervalRange(start, count, ...) with start > 0L and an inclusive end that exceeds Long.MAX_VALUE. Happens with high start values plus large counts.

Common situations: Emitting ranges near the end of the long domain; ID/sequence ranges seeded close to Long.MAX_VALUE; computed ranges never bounded.

Related errors


AI-assisted analysis of ReactiveX/RxJava@a8ab535614 (2026-08-13). Data as JSON: /api/errors/436b089f70a4b695. Report an issue: GitHub.