ReactiveX/RxJava · error · IllegalArgumentException
Integer overflow
Error message
Integer overflow
What it means
Thrown by Streamable.range when the inclusive endpoint start + (count - 1) exceeds Integer.MAX_VALUE. Because the operator emits ints, the range must fit in the int domain; the library casts to long to detect overflow safely and fails fast rather than wrapping.
Source
Thrown at src/main/java/io/reactivex/rxjava4/core/Streamable.java:496
* @param start the start element
* @param count the number of elements to emit
* @return the new {@code Streamable} instance
* @throws IllegalArgumentException if {@code count} is negative
*/
@CheckReturnValue
@NonNull
static Streamable<Integer> range(int start, int count) {
if (count < 0) {
throw new IllegalArgumentException("count >= 0 required but it was " + count);
} else
if (count == 0) {
return empty();
} else
if (count == 1) {
return just(start);
} else
if ((long)start + (count - 1) > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Integer overflow");
}
return RxJavaPlugins.onAssembly(new StreamableRange(start, count));
}
/**
* Emits elements from start up to start + count exclusive.
* @param start the start element
* @param count the number of elements to emit
* @return the new {@code Streamable} instance
* @throws IllegalArgumentException if {@code count} is negative
*/
@CheckReturnValue
@NonNull
static Streamable<Long> rangeLong(long start, long count) {
if (count < 0) {
throw new IllegalArgumentException("count >= 0 required but it was " + count);
}
View on GitHub (pinned to a8ab535614)
Solutions
- Reduce start and/or count so the inclusive end stays <= Integer.MAX_VALUE.
- Validate up front: boolean overflow = (long)start + (count - 1) > Integer.MAX_VALUE.
- Switch to Streamable.rangeLong if you need the long domain.
Example fix
// before Streamable.range(Integer.MAX_VALUE - 10, 100); // after // option A: clamp into the int domain int start = Integer.MAX_VALUE - 10; int count = Math.min(100, Integer.MAX_VALUE - start + 1); Streamable.range(start, count); // option B: move to the long domain Streamable.rangeLong((long)Integer.MAX_VALUE - 10, 100L);
Defensive patterns
Strategy: validation
Validate before calling
if ((long)start + (count - 1) > Integer.MAX_VALUE) {
count = Integer.MAX_VALUE - start + 1;
} Try / catch
try {
return Streamable.range(start, count);
} catch (IllegalArgumentException e) {
return Streamable.rangeLong((long)start, (long)count);
} Prevention
- Cast to long when validating the inclusive endpoint: (long)start + (count - 1).
- Avoid seeding start near Integer.MAX_VALUE.
- Prefer rangeLong when magnitudes may exceed the int domain.
When it happens
Trigger: Calling Streamable.range(start, count) where (long)start + (count - 1) > Integer.MAX_VALUE. Happens with high positive start values plus a large count.
Common situations: Generating ranges that cross the top of the int domain; counters near Integer.MAX_VALUE; unvalidated computed ranges.
Related errors
- Integer overflow
- Overflow! start + count is bigger than Long.MAX_VALUE
- Overflow! start + count is bigger than Long.MAX_VALUE
- Overflow! start + count is bigger than Long.MAX_VALUE
- count >= 0 required but it was {}
AI-assisted analysis of ReactiveX/RxJava@a8ab535614 (2026-08-13).
Data as JSON: /api/errors/f6d002102c0842c9.
Report an issue: GitHub.