quarkusio/quarkus · error · IllegalArgumentException

`%s` must be greater or equal to zero

Error message

`%s` must be greater or equal to zero

What it means

Validation.positiveOrZero(double, String) accepts 0 or positive amounts and rejects only negative values for Redis command arguments that permit zero (e.g. offsets, limits). A negative double triggers IllegalArgumentException before the command is sent.

Source

Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/datasource/Validation.java:130

    public static void validateTimeout(Duration value, String name) {
        if (value == null) {
            throw new IllegalArgumentException(String.format("`%s` must not be `null`", name));
        }
        if (value.isNegative()) {
            throw new IllegalArgumentException(String.format("`%s` must be greater than or equal to zero", name));
        }
    }

    public static void positive(double amount, String name) {
        if (amount <= 0) {
            throw new IllegalArgumentException(String.format("`%s` must be greater than zero`", name));
        }
    }

    public static void positiveOrZero(double amount, String name) {
        if (amount < 0) {
            throw new IllegalArgumentException(String.format("`%s` must be greater or equal to zero", name));
        }
    }

    public static void isBit(int b, String name) {
        if (b != 0 && b != 1) {
            throw new IllegalArgumentException(String.format("`%s` must be either `0` or `1`", name));
        }
    }

}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Clamp: double safe = Math.max(0, value) before the call
  2. Fix the pagination/index computation producing negative values
  3. Correct the negative value in the configuration source
  4. Treat -1e-9-scale underflow by snapping near-zero values to 0 (if (Math.abs(v) < epsilon) v = 0)

Example fix

// before
long offset = (page - 1) * size; // page=0 -> -size
redis.zrange(key, offset, offset + size - 1);
// after
long offset = Math.max(0, (page - 1) * size);
redis.zrange(key, offset, offset + size - 1);
Defensive patterns

Strategy: validation

Validate before calling

if (value < 0) throw new IllegalArgumentException("must be >= 0, got " + value);
double safe = Math.max(0, value);

Try / catch

try { redisCommand(offset); } catch (IllegalArgumentException e) { log.warn("Negative offset: {}", e.getMessage()); }

Prevention

When it happens

Trigger: Passing a negative double to an API that uses positiveOrZero validation, typically a negative offset/limit computed by subtracting values, or a negative config value like page-size=-5.

Common situations: Pagination math where (page-1)*size went negative for page=0; a negative value parsed from properties/YAML; floating-point underflow near zero (e.g. -1e-9 from iterative algorithms).

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/404263b1e42e02cb. Report an issue: GitHub.