{"record":{"id":"35ecf8f10a7a320e","repo":"quarkusio/quarkus","slug":"bits-must-be-strictly-positive","errorCode":null,"errorMessage":"`bits` must be strictly positive","messagePattern":"`bits` must be strictly positive","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/bitmap/BitFieldArgs.java","lineNumber":39,"sourceCode":"\n        public final boolean signed;\n        public final int bits;\n\n        public BitFieldType(String bit) {\n            if (bit.startsWith(\"i\")) {\n                this.signed = true;\n                this.bits = Integer.parseInt(bit.substring(1));\n            } else if (bit.startsWith(\"u\")) {\n                this.signed = false;\n                this.bits = Integer.parseInt(bit.substring(1));\n            }\n            throw new IllegalArgumentException(\"Invalid integer encoding for a bit field type: \" + bit +\n                    \". It must start with `i` (signed integers) or `u` (unsigned integers)\");\n        }\n\n        public BitFieldType(boolean signed, int bits) {\n            if (bits <= 0) {\n                throw new IllegalArgumentException(\"`bits` must be strictly positive\");\n            }\n\n            if (signed && bits >= 65) {\n                throw new IllegalArgumentException(\"Signed integers support only up to 64 bits\");\n            }\n            if (!signed && bits >= 64) {\n                throw new IllegalArgumentException(\"Unsigned integers support only up to 63 bits\");\n            }\n\n            this.signed = signed;\n            this.bits = bits;\n        }\n\n        @Override\n        public String toString() {\n            return (signed ? \"i\" : \"u\") + bits;\n        }\n","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/bitmap/BitFieldArgs.java#L21-L57","documentation":"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.","triggerScenarios":"new BitFieldArgs.BitFieldType(true, 0), BitFieldType(false, -8), or a parsed bits value of 0 (e.g. BitFieldType(\"i0\"), since Integer.parseInt(\"0\") succeeds).","commonSituations":"Computing the bit width from a variable that defaulted to 0; off-by-one when deriving width from a mask; misconfigured bit-width property.","solutions":["Pass a bit width of 1 or greater (signed: 1–64, unsigned: 1–63)","Validate/clamp the width before constructing the BitFieldType","Use the built-in factory constants (signIn8, unsignedIn32, etc.) with known-good widths"],"exampleFix":"// before\nint bits = 0;\nnew BitFieldArgs.BitFieldType(false, bits);\n// after\nint bits = 8;\nnew BitFieldArgs.BitFieldType(false, bits);","handlingStrategy":"validation","validationCode":"if (bits <= 0 || bits > (signed ? 64 : 63)) { throw new IllegalArgumentException(\"bits out of range\"); }\nnew BitFieldArgs.BitFieldType(signed, bits);","typeGuard":"static boolean isValidBitWidth(int bits) { return bits >= 1 && bits <= 64; }","tryCatchPattern":"try { type = new BitFieldArgs.BitFieldType(signed, bits); } catch (IllegalArgumentException e) { type = BitFieldArgs.BitFieldType.unsignedIn8(); }","preventionTips":["Clamp computed widths to 1..64","Prefer factory constants with fixed widths","Validate bit-width config values at startup"],"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-14T00:17:10.932Z"}