{"record":{"id":"1b4bae2ed8cfb520","repo":"quarkusio/quarkus","slug":"offset-must-be-greater-or-equal-to-0","errorCode":null,"errorMessage":"`offset` must be greater or equal to 0","messagePattern":"`offset` must be greater or equal to 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/bitmap/BitFieldArgs.java","lineNumber":148,"sourceCode":"     * @return the current {@code BitFieldArgs}\n     */\n    public BitFieldArgs get(BitFieldType bft, int offset) {\n        return get(bft, new Offset(false, offset));\n    }\n\n    /**\n     * Adds a new {@code GET} subcommand.\n     *\n     * @param bft the bit field type, must not be {@code null}.\n     * @param offset bitfield offset\n     * @return the current {@code BitFieldArgs}\n     */\n    public BitFieldArgs get(BitFieldType bft, Offset offset) {\n        if (offset == null) {\n            throw new IllegalArgumentException(\"`offset` must not be `null`\");\n        }\n        if (offset.offset < 0) {\n            throw new IllegalArgumentException(\"`offset` must be greater or equal to 0\");\n        }\n\n        this.previousBitFieldType = bft;\n        this.commands.addAll(List.of(\"GET\", bft.toString(), offset.toString()));\n        return this;\n    }\n\n    /**\n     * Adds a new {@code SET} subcommand.\n     *\n     * @param bft the bit field type, must not be {@code null}.\n     * @param offset bitfield offset\n     * @param value the value\n     * @return the current {@code BitFieldArgs}\n     */\n    public BitFieldArgs set(BitFieldType bft, int offset, long value) {\n        return set(bft, new Offset(false, offset), value);\n    }","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/bitmap/BitFieldArgs.java#L130-L166","documentation":"Thrown by BitFieldArgs.get when constructing a BITFIELD GET subcommand with an Offset whose underlying offset value is negative. Redis bitfield offsets address bits from the start of the string (or from the end when negative in Redis semantics, which this API models via the Offset(boolean, int) wrapper instead); passing a raw negative int to the typed Offset overload would address an invalid position, so the argument guard rejects it before the command is serialized.","triggerScenarios":"new BitFieldArgs.Offset(-1) or any negative offset passed to get(), often from a computed offset like byteIndex * 8 + shift where shift became negative.","commonSituations":"Arithmetic errors computing bit positions; confusing bit offset with byte index; underflow when subtracting offsets.","solutions":["Pass a bit offset >= 0 (offsets are in bits, from 0)","Clamp or validate the computed offset before constructing Offset","Use the Offset.byType(...) factories, which derive valid offsets from the field width"],"exampleFix":"// before\nint pos = index * 8 - 8; // can be -8 for index 0\nargs.get(bft, new BitFieldArgs.Offset(pos));\n// after\nint pos = Math.max(0, index * 8 - 8);\nargs.get(bft, new BitFieldArgs.Offset(pos));","handlingStrategy":"validation","validationCode":"if (offsetValue < 0) { throw new IllegalArgumentException(\"bit offset must be >= 0\"); }\nargs.get(bft, new BitFieldArgs.Offset(offsetValue));","typeGuard":"static boolean isValidOffset(long v) { return v >= 0; }","tryCatchPattern":"try { args.get(bft, new BitFieldArgs.Offset(pos)); } catch (IllegalArgumentException e) { pos = 0; args.get(bft, new BitFieldArgs.Offset(pos)); }","preventionTips":["Remember offsets are bits, not bytes","Clamp computed offsets with Math.max(0, ...)","Prefer Offset.byType(...) factories"],"tags":["redis","bitfield","argument-validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}