{"record":{"id":"a4ae09cc38a54768","repo":"ReactiveX/RxJava","slug":"count-0-required-but-it-was-a4ae09","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/Streamable.java","lineNumber":405,"sourceCode":"     * numbers from {@code start} up to {@code start + count} exclusive with the given period.\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 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>","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/ReactiveX/RxJava/blob/a8ab5356143f37a8f1dd6d76c79191bec5fa343b/src/main/java/io/reactivex/rxjava4/core/Streamable.java#L387-L423","documentation":"Thrown by Streamable.intervalRange (scheduler overload) when count is negative. The operator emits count longs starting at start; negative counts are invalid and rejected at assembly time. Note this overload validates unit/scheduler for null first, then count.","triggerScenarios":"Calling Streamable.intervalRange(start, count, initialDelay, period, unit, scheduler) with count < 0. Typical when count is computed or config-driven and can underflow.","commonSituations":"Config limits defaulting to -1; arithmetic like available - used that goes negative; untrusted inputs not bounds-checked.","solutions":["Bounds-check count before calling: if (count < 0L) handle or clamp to 0L.","Fix the upstream subtraction producing the negative value.","Return Streamable.empty() for count <= 0 instead of calling intervalRange."],"exampleFix":"// before\nlong count = quota - used; // can be negative\nStreamable.intervalRange(0, count, 0, 1, TimeUnit.SECONDS, scheduler);\n\n// after\nlong count = Math.max(0L, quota - used);\nStreamable<Long> s = count == 0L\n    ? Streamable.empty()\n    : Streamable.intervalRange(0, count, 0, 1, TimeUnit.SECONDS, scheduler);","handlingStrategy":"validation","validationCode":"if (count < 0L) {\n    return Streamable.empty();\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":["Bounds-check count before calling intervalRange.","Default unknown config limits to 0, not -1.","Clamp subtraction results before constructing the range."],"tags":["rxjava","streamable","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"}