quarkusio/quarkus · error · IllegalArgumentException

`count` must be strictly positive

Error message

`count` must be strictly positive

What it means

ScanArgs.count(long) sets the COUNT option of Redis SCAN/SSCAN/etc. The Redis protocol requires COUNT to be a positive number, so the builder validates the argument and throws IllegalArgumentException when count <= 0.

Source

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

import java.util.List;

/**
 * Represents the {@code scan} commands flags.
 */
public class ScanArgs {
    private long count = -1;
    private String match;

    /**
     * Sets the max number of items in each batch.
     * The default value is 10.
     *
     * @param count the number of item, must be strictly positive
     * @return the current {@code ScanArgs}
     */
    public ScanArgs count(long count) {
        if (count <= 0) {
            throw new IllegalArgumentException("`count` must be strictly positive");
        }
        this.count = count;
        return this;
    }

    /**
     * Sets a {@code MATCH} pattern
     *
     * @param pattern the pattern, must not be {@code null}
     * @return the current {@code ScanArgs}
     */
    public ScanArgs match(String pattern) {
        if (pattern == null) {
            throw new IllegalArgumentException("`pattern` must not be `null`");
        }
        this.match = pattern;
        return this;
    }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Pass a strictly positive value, e.g. scanArgs.count(100), or fix the computation producing 0/negative
  2. Guard with Math.max(1, configuredCount) before building ScanArgs
  3. Fix the configuration source so the batch-size property has a sane default (e.g. 10) instead of 0
  4. Validate config at startup (config mapping constraints) to fail early on non-positive values

Example fix

// before
long batchSize = total / pages; // can be 0
ScanArgs args = new ScanArgs().count(batchSize);
// after
long batchSize = Math.max(1, total / pages);
ScanArgs args = new ScanArgs().count(batchSize);
Defensive patterns

Strategy: validation

Validate before calling

if (count <= 0) throw new IllegalArgumentException("count must be > 0, got " + count);
ScanArgs args = new ScanArgs().count(count);

Try / catch

try {
    args = new ScanArgs().count(configuredCount);
} catch (IllegalArgumentException e) {
    args = new ScanArgs().count(10); // safe default
}

Prevention

When it happens

Trigger: Calling scanArgs.count(0) or scanArgs.count(negative value) before passing ScanArgs to a keys()/scan-style datasource method.

Common situations: Computing a batch size from configuration or a division that yields 0 (e.g. totalItems/pageSize with rounding); uninitialized config defaults of 0; off-by-one or sign bugs.

Related errors


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