quarkusio/quarkus · error · IllegalArgumentException

`bits` must be strictly positive

Error message

`bits` must be strictly positive

What it means

The BitFieldType constructor validates that the bit width is strictly positive; Redis bit fields require at least 1 bit. A zero or negative width is meaningless and rejected with IllegalArgumentException.

Source

Thrown at extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/bitmap/BitFieldArgs.java:39

        public final boolean signed;
        public final int bits;

        public BitFieldType(String bit) {
            if (bit.startsWith("i")) {
                this.signed = true;
                this.bits = Integer.parseInt(bit.substring(1));
            } else if (bit.startsWith("u")) {
                this.signed = false;
                this.bits = Integer.parseInt(bit.substring(1));
            }
            throw new IllegalArgumentException("Invalid integer encoding for a bit field type: " + bit +
                    ". It must start with `i` (signed integers) or `u` (unsigned integers)");
        }

        public BitFieldType(boolean signed, int bits) {
            if (bits <= 0) {
                throw new IllegalArgumentException("`bits` must be strictly positive");
            }

            if (signed && bits >= 65) {
                throw new IllegalArgumentException("Signed integers support only up to 64 bits");
            }
            if (!signed && bits >= 64) {
                throw new IllegalArgumentException("Unsigned integers support only up to 63 bits");
            }

            this.signed = signed;
            this.bits = bits;
        }

        @Override
        public String toString() {
            return (signed ? "i" : "u") + bits;
        }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Pass a bit width of 1 or greater (signed: 1–64, unsigned: 1–63)
  2. Validate/clamp the width before constructing the BitFieldType
  3. Use the built-in factory constants (signIn8, unsignedIn32, etc.) with known-good widths

Example fix

// before
int bits = 0;
new BitFieldArgs.BitFieldType(false, bits);
// after
int bits = 8;
new BitFieldArgs.BitFieldType(false, bits);
Defensive patterns

Strategy: validation

Validate before calling

if (bits <= 0 || bits > (signed ? 64 : 63)) { throw new IllegalArgumentException("bits out of range"); }
new BitFieldArgs.BitFieldType(signed, bits);

Type guard

static boolean isValidBitWidth(int bits) { return bits >= 1 && bits <= 64; }

Try / catch

try { type = new BitFieldArgs.BitFieldType(signed, bits); } catch (IllegalArgumentException e) { type = BitFieldArgs.BitFieldType.unsignedIn8(); }

Prevention

When it happens

Trigger: new BitFieldArgs.BitFieldType(true, 0), BitFieldType(false, -8), or a parsed bits value of 0 (e.g. BitFieldType("i0"), since Integer.parseInt("0") succeeds).

Common situations: Computing the bit width from a variable that defaulted to 0; off-by-one when deriving width from a mask; misconfigured bit-width property.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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