{"record":{"id":"afdfc2490ad55138","repo":"quarkusio/quarkus","slug":"the-offset-must-be-greater-or-equals-to-0","errorCode":null,"errorMessage":"The offset must be greater or equals to 0","messagePattern":"The offset must be greater or equals 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":181,"sourceCode":"     */\n    public BitFieldArgs set(BitFieldType bft, int offset, long value) {\n        return set(bft, new Offset(false, offset), value);\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, must not be {@code null}.\n     * @param value the value\n     * @return the current {@code BitFieldArgs}\n     */\n    public BitFieldArgs set(BitFieldType bft, Offset offset, long value) {\n        if (bft == null) {\n            throw new IllegalArgumentException(\"The BitFieldType must not be `null`\");\n        }\n        if (offset.offset < 0) {\n            throw new IllegalArgumentException(\"The offset must be greater or equals to 0\");\n        }\n\n        this.previousBitFieldType = bft;\n        this.commands.addAll(List.of(\"SET\", bft.toString(), offset.toString(), Long.toString(value)));\n        return this;\n    }\n\n    /**\n     * Adds a new {@code SET} subcommand using offset {@code 0} and the field type of the previous command.\n     *\n     * @param value the value\n     * @return the current {@code BitFieldArgs}\n     * @throws IllegalStateException if no previous field type was found\n     */\n    public BitFieldArgs set(long value) {\n        return set(getPreviousFieldType(), value);\n    }\n","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/bitmap/BitFieldArgs.java#L163-L199","documentation":"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).","triggerScenarios":"args.set(bft, new BitFieldArgs.Offset(negativeValue), value) — negative offsets from arithmetic errors or bad config.","commonSituations":"Computed bit positions underflowing; mixing byte offsets with bit offsets; decoding an offset from a string that produced a negative number.","solutions":["Pass a non-negative bit offset","Validate the computed position before constructing the Offset","Use Offset.byType(...) to derive offsets from field widths safely"],"exampleFix":"// before\nargs.set(bft, new BitFieldArgs.Offset(width - slotWidth), value); // can go negative\n// after\nlong pos = Math.max(0, width - slotWidth);\nargs.set(bft, new BitFieldArgs.Offset(pos), value);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(offset, \"offset required\");\nif (offset.offset < 0) { throw new IllegalArgumentException(\"offset must be >= 0\"); }\nargs.set(bft, offset, value);","typeGuard":"static boolean hasNonNegativeOffset(BitFieldArgs.Offset o) { return o != null; }","tryCatchPattern":"try { args.set(bft, offset, value); } catch (IllegalArgumentException e) { log.error(\"Bad BITFIELD offset: \" + e.getMessage()); }","preventionTips":["Clamp computed bit positions to >= 0","Distinguish bit offsets from byte offsets","Validate offsets right after computing them"],"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"}