{"record":{"id":"50bfa6119ec67e52","repo":"quarkusio/quarkus","slug":"the-expansion-factory-must-be-positive-50bfa6","errorCode":null,"errorMessage":"the expansion factory must be positive","messagePattern":"the expansion factory must be positive","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/bloom/BfReserveArgs.java","lineNumber":37,"sourceCode":"     */\n    public BfReserveArgs nonScaling() {\n        this.nonScaling = true;\n        return this;\n    }\n\n    /**\n     * Set the expansion factory.\n     * When capacity is reached, an additional sub-filter is created. The size of the new sub-filter is the size of\n     * the last sub-filter multiplied by expansion. If the number of elements to be stored in the filter is unknown,\n     * we recommend that you use an expansion of 2 or more to reduce the number of sub-filters. Otherwise, we recommend\n     * that you use an expansion of 1 to reduce memory consumption. The default expansion value is 2.\n     *\n     * @param expansion the expansion factor, must be positive\n     * @return the current {@link BfReserveArgs}\n     */\n    public BfReserveArgs expansion(int expansion) {\n        if (expansion <= 0) {\n            throw new IllegalArgumentException(\"the expansion factory must be positive\");\n        }\n        this.expansion = expansion;\n        return this;\n    }\n\n    @Override\n    public List<Object> toArgs() {\n        List<Object> list = new ArrayList<>();\n        if (expansion > 0) {\n            list.add(\"EXPANSION\");\n            list.add(Integer.toString(expansion));\n        }\n        if (nonScaling) {\n            list.add(\"NONSCALING\");\n        }\n        return list;\n    }\n}","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/bloom/BfReserveArgs.java#L19-L55","documentation":"BfReserveArgs.expansion(int) sets the EXPANSION option for the BF.RESERVE command when creating a scalable RedisBloom filter. The expansion factor must be strictly positive, so zero or negative values throw this IllegalArgumentException before any command reaches Redis.","triggerScenarios":"Calling BfReserveArgs.reserver(...).expansion(0) or a negative value — typically a zero-valued default from config or an uninitialized int field passed straight through.","commonSituations":"Creating filters from application configuration where the expansion property is missing and defaults to 0; computing the factor dynamically and getting <= 0; confusion with the NONSCALING option where expansion is irrelevant and left at 0.","solutions":["Pass a positive factor, e.g. expansion(2).","If the filter should not scale, use the NONSCALING variant instead of expansion(0).","Default the configured value: value <= 0 ? 2 : value."],"exampleFix":"// before\nBfReserveArgs args = BfReserveArgs.reserver(0.01).expansion(cfg.expansion()); // 0 -> throws\n// after\nBfReserveArgs args = BfReserveArgs.reserver(0.01).expansion(Math.max(1, cfg.expansion()));","handlingStrategy":"validation","validationCode":"int expansion = cfg.expansion();\nif (expansion <= 0) {\n    throw new IllegalArgumentException(\"BF.RESERVE expansion must be positive, got \" + expansion);\n}\nBfReserveArgs.args().expansion(expansion);","typeGuard":null,"tryCatchPattern":"try { reserveArgs.expansion(f); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"expansion\")) { reserveArgs.expansion(2); } else { throw e; } }","preventionTips":["Default expansion to 2 when the config value is absent.","Use the NONSCALING option instead of expansion(0) for non-scaling filters.","Fail fast at startup if the configured expansion is non-positive."],"tags":["redis","bloom-filter","argument-validation"],"backgroundTag":"invalid-argument-value","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"}