ReactiveX/RxJava · error · IllegalArgumentException

{paramName} > 0 required but it was {value}

Error message

{paramName} > 0 required but it was {value}

What it means

Thrown by ObjectHelper.verifyPositive(int, String) when value <= 0. This helper validates buffer sizes, prefetch amounts, concurrency limits, and other strictly-positive integer parameters across the library, embedding the offending parameter name in the message for easy diagnosis.

Source

Thrown at src/main/java/io/reactivex/rxjava4/internal/functions/ObjectHelper.java:52

     * @param <T> the value type
     * @return the bi-predicate instance
     */
    @SuppressWarnings("unchecked")
    public static <T> BiPredicate<T, T> equalsPredicate() {
        return (BiPredicate<T, T>)EQUALS;
    }

    /**
     * Validate that the given value is positive or report an IllegalArgumentException with
     * the parameter name.
     * @param value the value to validate
     * @param paramName the parameter name of the value
     * @return value
     * @throws IllegalArgumentException if bufferSize &lt;= 0
     */
    public static int verifyPositive(int value, String paramName) {
        if (value <= 0) {
            throw new IllegalArgumentException(paramName + " > 0 required but it was " + value);
        }
        return value;
    }

    /**
     * Validate that the given value is positive or report an IllegalArgumentException with
     * the parameter name.
     * @param value the value to validate
     * @param paramName the parameter name of the value
     * @return value
     * @throws IllegalArgumentException if bufferSize &lt;= 0
     */
    public static long verifyPositive(long value, String paramName) {
        if (value <= 0L) {
            throw new IllegalArgumentException(paramName + " > 0 required but it was " + value);
        }
        return value;
    }

View on GitHub (pinned to a8ab535614)

Solutions

  1. Ensure the int value is >= 1 before invoking the operator; clamp with Math.max(1, value).
  2. Fix the config/source so the value cannot be non-positive (reject 0/-1 at parse time).
  3. Pick a sensible positive default (e.g. 128 for buffers) when the configured value is absent or invalid.
  4. Add a boundary test: value 1 succeeds, value 0 throws, negative throws.

Example fix

// before
int buf = config.getInt("buffer", 0);
source.buffer(buf).blockingSubscribe(...);

// after
int buf = Math.max(1, config.getInt("buffer", 128));
source.buffer(buf).blockingSubscribe(...);
Defensive patterns

Strategy: validation

Validate before calling

int safePositive(int v, String name) {
    return ObjectHelper.verifyPositive(Math.max(1, v), name);
}
// or simply: int buf = Math.max(1, configured);

Try / catch

try {
    source.buffer(buf).blockingSubscribe(...);
} catch (IllegalArgumentException e) {
    // buf <= 0; pick a positive default and retry
}

Prevention

When it happens

Trigger: Calling an operator that internally delegates to verifyPositive with a non-positive int: e.g. buffer(capacity) with capacity <= 0, flowableOnBackpressureBuffer(capacity) with capacity <= 0, or any API whose @param documents 'positive'. Also triggered by calling verifyPositive directly.

Common situations: Config-driven buffer/prefetch sizes defaulting to 0 or -1 when unset; computing capacity from expressions that can reach zero (e.g. pool size minus reserve); passing a literal 0 by mistake instead of a meaningful default.

Related errors


AI-assisted analysis of ReactiveX/RxJava@a8ab535614 (2026-08-13). Data as JSON: /api/errors/9b8c7e69aff38b03. Report an issue: GitHub.