{"record":{"id":"e6ef7d3628095c15","repo":"ReactiveX/RxJava","slug":"count-0-required-but-it-was","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/Flowable.java","lineNumber":2403,"sourceCode":"     * @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 {@code Scheduler} where the values and terminal signals will be emitted\n     * @return the new {@code Flowable} instance\n     * @throws NullPointerException if {@code unit} or {@code scheduler} is {@code null}\n     * @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>","sourceCodeStart":2385,"sourceCodeEnd":2421,"githubUrl":"https://github.com/ReactiveX/RxJava/blob/a8ab5356143f37a8f1dd6d76c79191bec5fa343b/src/main/java/io/reactivex/rxjava4/core/Flowable.java#L2385-L2421","documentation":"Thrown by Flowable.intervalRange when the count argument is negative. intervalRange emits count longs starting at start; a negative count is meaningless and is rejected eagerly before any scheduling begins. The message interpolates the offending value so the caller can see exactly what was passed.","triggerScenarios":"Calling Flowable.intervalRange(start, count, ...) with count < 0L. Typically the count comes from a config value, a computed size, or an off-by-one subtraction that yields -1.","commonSituations":"Config-driven paging where limit/pageSize is unset and defaults to -1; size calculations like list.size() - threshold that go negative; deserialized values that were never bounds-checked.","solutions":["Bounds-check count before the call: if (count < 0L) handle the error or clamp to 0L.","Fix the upstream computation producing the negative value (e.g., guard list.size() - offset).","Default missing/unknown config to 0L rather than -1 so intervalRange returns an empty Flowable."],"exampleFix":"// before\nlong count = pageSize - offset; // can be negative\nFlowable.intervalRange(0, count, 0, 1, TimeUnit.SECONDS, scheduler);\n\n// after\nlong count = pageSize - offset;\nFlowable<Long> f = count < 0L\n    ? Flowable.empty()\n    : Flowable.intervalRange(0, count, 0, 1, TimeUnit.SECONDS, scheduler);","handlingStrategy":"validation","validationCode":"if (count < 0L) {\n    // avoid Flowable.intervalRange throwing\n    return Flowable.empty();\n}","typeGuard":null,"tryCatchPattern":"try {\n    return Flowable.intervalRange(start, count, initialDelay, period, unit, scheduler);\n} catch (IllegalArgumentException e) {\n    // log and degrade to empty rather than crash\n    return Flowable.empty();\n}","preventionTips":["Bounds-check any count derived from subtraction or config before calling intervalRange.","Default unknown config limits to 0, not -1.","Encapsulate range construction behind a helper that clamps negatives to 0."],"tags":["rxjava","flowable","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"}