quarkusio/quarkus · error · IllegalArgumentException

`%s` must be either `0` or `1`

Error message

`%s` must be either `0` or `1`

What it means

Validation.isBit checks that an int argument used where Redis expects a bit value (SETBIT value, BITFIELD, BITCOUNT range semantics) is exactly 0 or 1. Any other int is rejected locally with IllegalArgumentException naming the parameter.

Source

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

            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. Convert with (value != 0 ? 1 : 0) before the call
  2. If input is a boolean, pass it as boolean and let the API map it, or use value ? 1 : 0
  3. Validate parsed user input is exactly "0" or "1" before parseInt
  4. Mask raw bytes with & 1 when only the lowest bit is meaningful

Example fix

// before
redis.setbit("flags", 3, byteValue); // byteValue may be e.g. 49
// after
redis.setbit("flags", 3, byteValue != 0 ? 1 : 0);
Defensive patterns

Strategy: validation

Validate before calling

static boolean isBit(int b) { return b == 0 || b == 1; }
if (!isBit(b)) throw new IllegalArgumentException("not a bit: " + b);
int bit = b != 0 ? 1 : 0;

Try / catch

try { redis.setbit(key, offset, b); } catch (IllegalArgumentException e) { log.warn("Value {} is not a bit", b); }

Prevention

When it happens

Trigger: Calling setbit(key, offset, value) or related bit APIs with an int that is not 0/1, e.g. passing a boolean-as-int from parsing ('true' -> -1 or 10), a raw byte with high bits, or a counter value instead of a bit.

Common situations: Passing Boolean hashCode or an ASCII '0'/'1' character code (48/49) instead of the numeric bit; converting user input with Integer.parseInt("01") is fine but parseInt("2") is not; bitmasking results that yield values > 1.

Related errors


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