{"record":{"id":"371544392b6f3c7b","repo":"ReactiveX/RxJava","slug":"count-0-required-but-it-was-371544","errorCode":null,"errorMessage":"count >= 0 required but it was {}","messagePattern":"count >= 0 required but it was (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/reactivex/rxjava4/core/Observable.java","lineNumber":2090,"sourceCode":"     * </dl>\n     * @param start that start value of the range\n     * @param count the number of values to emit in total, if zero, the operator emits an {@code onComplete} after the initial delay.\n     * @param initialDelay the initial delay before signaling the first value (the start)\n     * @param period the period between subsequent values\n     * @param unit the unit of measure of the {@code initialDelay} and {@code period} amounts\n     * @param scheduler the target scheduler where the values and terminal signals will be emitted\n     * @return the new {@code Observable} instance\n     * @throws NullPointerException if {@code unit} or {@code scheduler} is {@code null}\n     * @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.","sourceCodeStart":2072,"sourceCodeEnd":2108,"githubUrl":"https://github.com/ReactiveX/RxJava/blob/a8ab5356143f37a8f1dd6d76c79191bec5fa343b/src/main/java/io/reactivex/rxjava4/core/Observable.java#L2072-L2108","documentation":"Thrown by Observable.intervalRange when count is negative. The operator emits count longs; a negative count is invalid and rejected at assembly time before any scheduling. The offending value is interpolated into the message.","triggerScenarios":"Calling Observable.intervalRange(start, count, ...) with count < 0. Typical when count is derived from a computation or config that can go negative.","commonSituations":"Config-driven emission counts defaulting to -1; size calculations like available - consumed that underflow; untrusted inputs not bounds-checked.","solutions":["Validate count before the call: if (count < 0) handle the error or clamp to 0.","Fix the upstream arithmetic producing the negative value.","Default unknown counts to 0 so you get Observable.empty() behavior."],"exampleFix":"// before\nlong count = remaining - 1; // can be negative\nObservable.intervalRange(0, count, 0, 1, TimeUnit.SECONDS, scheduler);\n\n// after\nlong count = remaining - 1;\nObservable<Long> o = count < 0L\n    ? Observable.empty()\n    : Observable.intervalRange(0, count, 0, 1, TimeUnit.SECONDS, scheduler);","handlingStrategy":"validation","validationCode":"if (count < 0L) {\n    return Observable.empty();\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":["Bounds-check count before calling intervalRange.","Default unknown config limits to 0, not -1.","Wrap intervalRange construction in a helper that clamps negatives."],"tags":["rxjava","observable","interval-range","argument-validation","arithmetic"],"backgroundTag":null,"analyzedSha":"a8ab5356143f37a8f1dd6d76c79191bec5fa343b","analyzedAt":"2026-08-13T23:25:30.069Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}