{"record":{"id":"0d5db4be985ca34a","repo":"quarkusio/quarkus","slug":"distance-must-be-in-1-4","errorCode":null,"errorMessage":"`distance` must be in [1,4]","messagePattern":"`distance` must be in \\[1,4\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/search/SpellCheckArgs.java","lineNumber":28,"sourceCode":"import io.smallrye.mutiny.helpers.ParameterValidation;\n\npublic class SpellCheckArgs implements RedisCommandExtraArguments {\n\n    private int distance;\n\n    private final List<String> includes = new ArrayList<>();\n    private final List<String> excludes = new ArrayList<>();\n    private int dialect = -1;\n\n    /**\n     * Sets the maximum Levenshtein distance for spelling suggestions (default: 1, max: 4).\n     *\n     * @param distance the distance\n     * @return the current {@code SpellCheckArgs}\n     */\n    public SpellCheckArgs distance(int distance) {\n        if (distance < 1 || distance > 4) {\n            throw new IllegalArgumentException(\"`distance` must be in [1,4]\");\n        }\n        this.distance = distance;\n        return this;\n    }\n\n    /**\n     * Specifies an inclusion of a custom dictionary named {@code dict}\n     *\n     * @param dict the dictionaries\n     * @return the current {@code SpellCheckArgs}\n     */\n    public SpellCheckArgs includes(String... dict) {\n        ParameterValidation.doesNotContainNull(notNullOrEmpty(dict, \"dict\"), \"dict\");\n        Collections.addAll(includes, dict);\n        return this;\n    }\n\n    /**","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/search/SpellCheckArgs.java#L10-L46","documentation":"SpellCheckArgs.distance(int) validates that the FT.SPELLCHECK DISTANCE parameter is between 1 and 4, matching RediSearch's allowed range. The library throws IllegalArgumentException eagerly at argument-construction time rather than sending an invalid value to Redis. Values outside [1,4] have no meaning in RediSearch's Levenshtein distance model.","triggerScenarios":"Calling new SpellCheckArgs().distance(0) or .distance(5) or any negative value before executing a spellcheck query.","commonSituations":"Developers guess that distance 0 means 'exact match only' or copy a Levenshtein threshold from another library; assuming the range is inclusive of 0 or unbounded above.","solutions":["Pass a distance value between 1 and 4 inclusive, e.g. args.distance(2)","If 'no fuzzy matching' is desired, do not call distance() at all or skip spellcheck for that term","Clamp the user-supplied value: Math.max(1, Math.min(4, userDistance))"],"exampleFix":"// before\nSpellCheckArgs args = new SpellCheckArgs().distance(0);\n// after\nSpellCheckArgs args = new SpellCheckArgs().distance(1);","handlingStrategy":"validation","validationCode":"if (distance < 1 || distance > 4) throw new IllegalArgumentException(\"distance must be in [1,4]\");\nargs.distance(distance);","typeGuard":"boolean isValidDistance(int d) { return d >= 1 && d <= 4; }","tryCatchPattern":null,"preventionTips":["Remember RediSearch spellcheck distance is 1-4 inclusive","Never assume 0 disables fuzzy matching; omit distance() instead","Clamp external/user input before calling distance()"],"tags":["redis","redisearch","argument-validation","spellcheck"],"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"}