quarkusio/quarkus · error · IllegalArgumentException

The offset must be greater or equals to 0

Error message

The offset must be greater or equals to 0

What it means

In set(), the offset's numeric value is validated to be >= 0 before building the SET sub-command, since Redis bit-field offsets cannot be negative. Note this branch assumes offset itself is non-null (a null offset here would instead throw a NullPointerException dereferencing offset.offset).

Source

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

     */
    public BitFieldArgs set(BitFieldType bft, int offset, long value) {
        return set(bft, new Offset(false, offset), value);
    }

    /**
     * Adds a new {@code SET} subcommand.
     *
     * @param bft the bit field type, must not be {@code null}.
     * @param offset bitfield offset, must not be {@code null}.
     * @param value the value
     * @return the current {@code BitFieldArgs}
     */
    public BitFieldArgs set(BitFieldType bft, Offset offset, long value) {
        if (bft == null) {
            throw new IllegalArgumentException("The BitFieldType must not be `null`");
        }
        if (offset.offset < 0) {
            throw new IllegalArgumentException("The offset must be greater or equals to 0");
        }

        this.previousBitFieldType = bft;
        this.commands.addAll(List.of("SET", bft.toString(), offset.toString(), Long.toString(value)));
        return this;
    }

    /**
     * Adds a new {@code SET} subcommand using offset {@code 0} and the field type of the previous command.
     *
     * @param value the value
     * @return the current {@code BitFieldArgs}
     * @throws IllegalStateException if no previous field type was found
     */
    public BitFieldArgs set(long value) {
        return set(getPreviousFieldType(), value);
    }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Pass a non-negative bit offset
  2. Validate the computed position before constructing the Offset
  3. Use Offset.byType(...) to derive offsets from field widths safely

Example fix

// before
args.set(bft, new BitFieldArgs.Offset(width - slotWidth), value); // can go negative
// after
long pos = Math.max(0, width - slotWidth);
args.set(bft, new BitFieldArgs.Offset(pos), value);
Defensive patterns

Strategy: validation

Validate before calling

Objects.requireNonNull(offset, "offset required");
if (offset.offset < 0) { throw new IllegalArgumentException("offset must be >= 0"); }
args.set(bft, offset, value);

Type guard

static boolean hasNonNegativeOffset(BitFieldArgs.Offset o) { return o != null; }

Try / catch

try { args.set(bft, offset, value); } catch (IllegalArgumentException e) { log.error("Bad BITFIELD offset: " + e.getMessage()); }

Prevention

When it happens

Trigger: args.set(bft, new BitFieldArgs.Offset(negativeValue), value) — negative offsets from arithmetic errors or bad config.

Common situations: Computed bit positions underflowing; mixing byte offsets with bit offsets; decoding an offset from a string that produced a negative number.

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/afdfc2490ad55138. Report an issue: GitHub.