{"record":{"id":"115476822963c63f","repo":"quarkusio/quarkus","slug":"s-must-be-either-0-or-1","errorCode":null,"errorMessage":"`%s` must be either `0` or `1`","messagePattern":"`(.+?)` must be either `0` or `1`","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/datasource/Validation.java","lineNumber":136,"sourceCode":"            throw new IllegalArgumentException(String.format(\"`%s` must be greater than or equal to zero\", name));\n        }\n    }\n\n    public static void positive(double amount, String name) {\n        if (amount <= 0) {\n            throw new IllegalArgumentException(String.format(\"`%s` must be greater than zero`\", name));\n        }\n    }\n\n    public static void positiveOrZero(double amount, String name) {\n        if (amount < 0) {\n            throw new IllegalArgumentException(String.format(\"`%s` must be greater or equal to zero\", name));\n        }\n    }\n\n    public static void isBit(int b, String name) {\n        if (b != 0 && b != 1) {\n            throw new IllegalArgumentException(String.format(\"`%s` must be either `0` or `1`\", name));\n        }\n    }\n\n}\n","sourceCodeStart":118,"sourceCodeEnd":141,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/datasource/Validation.java#L118-L141","documentation":"Validation.isBit checks that an int argument used where Redis expects a bit value (SETBIT value, BITFIELD, BITCOUNT range semantics) is exactly 0 or 1. Any other int is rejected locally with IllegalArgumentException naming the parameter.","triggerScenarios":"Calling setbit(key, offset, value) or related bit APIs with an int that is not 0/1, e.g. passing a boolean-as-int from parsing ('true' -> -1 or 10), a raw byte with high bits, or a counter value instead of a bit.","commonSituations":"Passing Boolean hashCode or an ASCII '0'/'1' character code (48/49) instead of the numeric bit; converting user input with Integer.parseInt(\"01\") is fine but parseInt(\"2\") is not; bitmasking results that yield values > 1.","solutions":["Convert with (value != 0 ? 1 : 0) before the call","If input is a boolean, pass it as boolean and let the API map it, or use value ? 1 : 0","Validate parsed user input is exactly \"0\" or \"1\" before parseInt","Mask raw bytes with & 1 when only the lowest bit is meaningful"],"exampleFix":"// before\nredis.setbit(\"flags\", 3, byteValue); // byteValue may be e.g. 49\n// after\nredis.setbit(\"flags\", 3, byteValue != 0 ? 1 : 0);","handlingStrategy":"validation","validationCode":"static boolean isBit(int b) { return b == 0 || b == 1; }\nif (!isBit(b)) throw new IllegalArgumentException(\"not a bit: \" + b);\nint bit = b != 0 ? 1 : 0;","typeGuard":null,"tryCatchPattern":"try { redis.setbit(key, offset, b); } catch (IllegalArgumentException e) { log.warn(\"Value {} is not a bit\", b); }","preventionTips":["Always normalize ints to 0/1 with a ternary before bit APIs","Don't pass char codes ('0'=48) or Boolean.hashCode as bits","Mask raw data with & 1 when only the low bit matters","Type-check inputs: prefer boolean overloads if available"],"tags":["redis","validation","illegal-argument","bitwise"],"backgroundTag":"invalid-argument-range","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"}