{"record":{"id":"5bad813576e7c475","repo":"ReactiveX/RxJava","slug":"overflow-start-count-is-bigger-than-long-max-va-5bad81","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/Streamable.java","lineNumber":410,"sourceCode":"     * @param initialDelay the time to delay before the {@code start} item is emitted\n     * @param period the period of how often emit the next item\n     * @param unit the time unit for both {@code initialDelay} and {@code period}\n     * @param scheduler the scheduler to use for the timed waiting\n     * @return the new {@code Streamable} instance\n     * @throws NullPointerException if {@code unit} or {@code scheduler} is {@code null}\n     * @throws IllegalArgumentException if {@code count} is negative\n     */\n    static Streamable<Long> intervalRange(long start, long count,\n            long initialDelay, long period, TimeUnit unit, Scheduler scheduler) {\n        Objects.requireNonNull(unit, \"unit is null\");\n        Objects.requireNonNull(scheduler, \"scheduler is null\");\n        if (count < 0) {\n            throw new IllegalArgumentException(\"count >= 0 required but it was \" + count);\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\n        return RxJavaPlugins.onAssembly(new StreamableIntervalRange(start, count, initialDelay, period, unit, scheduler, null));\n    }\n\n    /**\n     * Constructs a {@code Streamable} that after the initial delay, starts emitting an ever increasing\n     * numbers from {@code start} up to {@code start + count} exclusive with the given period.\n     * <p>\n     * If the provided {@link ExecutorService} is a {@link ScheduledExecutorService}, its\n     * {@link ScheduledExecutorService#scheduleAtFixedRate(Runnable, long, long, TimeUnit)} will be used.\n     * Otherwise, a plain {@code ExecutorService} will be wrapped via {@link Schedulers#from(Executor)}.\n     * <p>\n     * If there are processing delays, this source may emit multiple queued up items in a quick succession.\n     * @param start the first long value to emit\n     * @param count the number of items to emit, use {@link Long#MAX_VALUE} for an unlimited range\n     * @param initialDelay the time to delay before the {@code start} item is emitted\n     * @param period the period of how often emit the next itme","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/ReactiveX/RxJava/blob/a8ab5356143f37a8f1dd6d76c79191bec5fa343b/src/main/java/io/reactivex/rxjava4/core/Streamable.java#L392-L428","documentation":"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.","triggerScenarios":"Calling Streamable.intervalRange(start, count, initialDelay, period, unit, scheduler) with start > 0L and an inclusive end exceeding Long.MAX_VALUE.","commonSituations":"Sequences seeded near Long.MAX_VALUE; computed ranges never bounded; ID/counter ranges at the top of the long domain.","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."],"exampleFix":"// before\nlong start = Long.MAX_VALUE - 5;\nStreamable.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);\nStreamable.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 Streamable.intervalRange(start, count, initialDelay, period, unit, scheduler);\n} catch (IllegalArgumentException e) {\n    return Streamable.empty();\n}","preventionTips":["Bound start away from Long.MAX_VALUE when count is large.","Apply the wraparound check before calling.","Page large ranges into smaller chunks."],"tags":["rxjava","streamable","interval-range","overflow","arithmetic"],"backgroundTag":null,"analyzedSha":"a8ab5356143f37a8f1dd6d76c79191bec5fa343b","analyzedAt":"2026-08-13T23:25:30.069Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}