{"record":{"id":"11c0e99e2334ddbd","repo":"ReactiveX/RxJava","slug":"overflow-start-count-is-bigger-than-long-max-va","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/Flowable.java","lineNumber":2411,"sourceCode":"     * @throws IllegalArgumentException\n     *             if {@code count} is less than zero, or if {@code start} + {@code count} &minus; 1 exceeds\n     *             {@link Long#MAX_VALUE}\n     */\n    @CheckReturnValue\n    @NonNull\n    @BackpressureSupport(BackpressureKind.ERROR)\n    @SchedulerSupport(SchedulerSupport.CUSTOM)\n    public static Flowable<Long> intervalRange(long start, long count, long initialDelay, long period, @NonNull TimeUnit unit, @NonNull Scheduler scheduler) {\n        if (count < 0L) {\n            throw new IllegalArgumentException(\"count >= 0 required but it was \" + count);\n        }\n        if (count == 0L) {\n            return Flowable.<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 FlowableIntervalRange(start, end, Math.max(0L, initialDelay), Math.max(0L, period), unit, scheduler));\n    }\n\n    /**\n     * Returns a {@code Flowable} that signals the given (constant reference) item and then completes.\n     * <p>\n     * <img width=\"640\" height=\"310\" src=\"https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/just.v3.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 Subscriber}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":2393,"sourceCodeEnd":2429,"githubUrl":"https://github.com/ReactiveX/RxJava/blob/a8ab5356143f37a8f1dd6d76c79191bec5fa343b/src/main/java/io/reactivex/rxjava4/core/Flowable.java#L2393-L2429","documentation":"Thrown by Flowable.intervalRange when start + (count - 1) would overflow Long.MAX_VALUE. The library computes the inclusive end and detects wraparound by checking that a positive start produced a negative end. It fails fast rather than emitting a corrupted (negative) sequence.","triggerScenarios":"Calling Flowable.intervalRange(start, count, ...) with start > 0L and start + (count - 1) exceeding Long.MAX_VALUE (end wraps to negative). Happens with very large start values combined with a large count.","commonSituations":"Paging over ID ranges near Long.MAX_VALUE; monotonic counters seeded near the top of the long range; computed ranges whose magnitude was never bounded.","solutions":["Cap or reduce start and/or count so the inclusive end stays <= Long.MAX_VALUE.","Validate the range up front: boolean overflow = start > 0L && Long.MAX_VALUE - (count - 1) < start.","Use a smaller count, or page the emission in chunks."],"exampleFix":"// before\nlong start = Long.MAX_VALUE - 10;\nFlowable.intervalRange(start, 100L, 0, 1, TimeUnit.SECONDS, scheduler);\n\n// after\nlong start = Long.MAX_VALUE - 10;\nlong count = Math.min(100L, Long.MAX_VALUE - start + 1);\nFlowable.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    // clamp count so the inclusive end stays within Long.MAX_VALUE\n    count = Long.MAX_VALUE - start + 1;\n}","typeGuard":null,"tryCatchPattern":"try {\n    return Flowable.intervalRange(start, count, initialDelay, period, unit, scheduler);\n} catch (IllegalArgumentException e) {\n    // reduce the range and retry, or signal empty\n    return Flowable.empty();\n}","preventionTips":["Never seed start near Long.MAX_VALUE without bounding count.","Use the end-wraparound check (start > 0 && start + (count-1) < 0) before calling.","Page large ranges into chunks instead of one huge intervalRange."],"tags":["rxjava","flowable","interval-range","overflow","arithmetic"],"backgroundTag":null,"analyzedSha":"a8ab5356143f37a8f1dd6d76c79191bec5fa343b","analyzedAt":"2026-08-13T23:25:30.069Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}