{"record":{"id":"436b089f70a4b695","repo":"ReactiveX/RxJava","slug":"overflow-start-count-is-bigger-than-long-max-va-436b08","errorCode":null,"errorMessage":"Overflow! start + count is bigger than Long.MAX_VALUE","messagePattern":"Overflow! start \\+ count is bigger than Long\\.MAX_VALUE","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/reactivex/rxjava4/core/Observable.java","lineNumber":2099,"sourceCode":"     * @throws IllegalArgumentException\n     *             if {@code count} is negative, or if {@code start} + {@code count} &minus; 1 exceeds\n     *             {@link Long#MAX_VALUE}\n     */\n    @CheckReturnValue\n    @NonNull\n    @SchedulerSupport(SchedulerSupport.CUSTOM)\n    public static Observable<Long> intervalRange(long start, long count, long initialDelay, long period, @NonNull TimeUnit unit, @NonNull Scheduler scheduler) {\n        if (count < 0) {\n            throw new IllegalArgumentException(\"count >= 0 required but it was \" + count);\n        }\n\n        if (count == 0L) {\n            return Observable.<Long>empty().delay(initialDelay, unit, scheduler);\n        }\n\n        long end = start + (count - 1);\n        if (start > 0 && end < 0) {\n            throw new IllegalArgumentException(\"Overflow! start + count is bigger than Long.MAX_VALUE\");\n        }\n        Objects.requireNonNull(unit, \"unit is null\");\n        Objects.requireNonNull(scheduler, \"scheduler is null\");\n\n        return RxJavaPlugins.onAssembly(new ObservableIntervalRange(start, end, Math.max(0L, initialDelay), Math.max(0L, period), unit, scheduler));\n    }\n\n    /**\n     * Returns an {@code Observable} that signals the given (constant reference) item and then completes.\n     * <p>\n     * <img width=\"640\" height=\"290\" src=\"https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/just.item.png\" alt=\"\">\n     * <p>\n     * Note that the item is taken and re-emitted as is and not computed by any means by {@code just}. Use {@link #fromCallable(Callable)}\n     * to generate a single item on demand (when {@link Observer}s subscribe to it).\n     * <p>\n     * See the multi-parameter overloads of {@code just} to emit more than one (constant reference) items one after the other.\n     * Use {@link #fromArray(Object...)} to emit an arbitrary number of items that are known upfront.\n     * <p>","sourceCodeStart":2081,"sourceCodeEnd":2117,"githubUrl":"https://github.com/ReactiveX/RxJava/blob/a8ab5356143f37a8f1dd6d76c79191bec5fa343b/src/main/java/io/reactivex/rxjava4/core/Observable.java#L2081-L2117","documentation":"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.","triggerScenarios":"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.","commonSituations":"Emitting ranges near the end of the long domain; ID/sequence ranges seeded close to Long.MAX_VALUE; computed ranges never bounded.","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 if you need that magnitude."],"exampleFix":"// before\nlong start = Long.MAX_VALUE - 5;\nObservable.intervalRange(start, 50L, 0, 1, TimeUnit.SECONDS, scheduler);\n\n// after\nlong start = Long.MAX_VALUE - 5;\nlong count = Math.min(50L, Long.MAX_VALUE - start + 1);\nObservable.intervalRange(start, count, 0, 1, TimeUnit.SECONDS, scheduler);","handlingStrategy":"validation","validationCode":"long end = start + (count - 1);\nboolean overflow = start > 0L && end < 0L;\nif (overflow) {\n    count = Long.MAX_VALUE - start + 1;\n}","typeGuard":null,"tryCatchPattern":"try {\n    return Observable.intervalRange(start, count, initialDelay, period, unit, scheduler);\n} catch (IllegalArgumentException e) {\n    return Observable.empty();\n}","preventionTips":["Bound start away from Long.MAX_VALUE when planning a large count.","Apply the wraparound check before calling.","Page large ranges into smaller chunks."],"tags":["rxjava","observable","interval-range","overflow","arithmetic"],"backgroundTag":null,"analyzedSha":"a8ab5356143f37a8f1dd6d76c79191bec5fa343b","analyzedAt":"2026-08-13T23:25:30.069Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}