quarkusio/quarkus · error · IllegalArgumentException

the expansion factory must be positive

Error message

the expansion factory must be positive

What it means

BfInsertArgs.expansion(int) sets the BF.INSERT EXPANSION option for RedisBloom filters. The expansion factor (how each new sub-filter scales) must be a positive integer, so the method throws this IllegalArgumentException for zero or negative values, matching RedisBloom's own semantics.

Source

Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/bloom/BfInsertArgs.java:78

     */
    public BfInsertArgs nonScaling() {
        this.nonScaling = true;
        return this;
    }

    /**
     * Set the expansion factory.
     * When capacity is reached, an additional sub-filter is created. The size of the new sub-filter is the size of
     * the last sub-filter multiplied by expansion. If the number of elements to be stored in the filter is unknown,
     * we recommend that you use an expansion of 2 or more to reduce the number of sub-filters. Otherwise, we recommend
     * that you use an expansion of 1 to reduce memory consumption. The default expansion value is 2.
     *
     * @param expansion the expansion factor, must be positive
     * @return the current {@link BfInsertArgs}
     */
    public BfInsertArgs expansion(int expansion) {
        if (expansion <= 0) {
            throw new IllegalArgumentException("the expansion factory must be positive");
        }
        this.expansion = expansion;
        return this;
    }

    @Override
    public List<Object> toArgs() {
        List<Object> list = new ArrayList<>();

        if (capacity > 0) {
            list.add("CAPACITY");
            list.add(Long.toString(capacity));
        }

        if (errorRate != -1.0) {
            list.add("ERROR");
            list.add(new BigDecimal(errorRate).toPlainString()); // Prevent E notation
        }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Pass a positive integer, e.g. expansion(2) (the common doubling strategy).
  2. Clamp or default the value before calling: value <= 0 ? 2 : value.
  3. Fix the configuration source that supplies the expansion factor.

Example fix

// before
args.expansion(config.expansion()); // 0 when unset -> throws
// after
args.expansion(config.expansion() > 0 ? config.expansion() : 2);
Defensive patterns

Strategy: validation

Validate before calling

int expansion = config.expansion();
if (expansion <= 0) {
    expansion = 2; // standard doubling
}
args.expansion(expansion);

Try / catch

try { args.expansion(expansion); } catch (IllegalArgumentException e) { if (e.getMessage().contains("expansion")) { args.expansion(2); } else { throw e; } }

Prevention

When it happens

Trigger: Calling bfInsertArgs.expansion(0) or expansion(-1) — usually because the expansion value came from configuration, an environment variable, or arithmetic that yielded <= 0.

Common situations: Unset config defaulting to 0 and being passed through unchanged; a division or subtraction producing a non-positive factor; copying constants from another bloom config where the field means something else.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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