{"record":{"id":"595b4bc890f3c54c","repo":"redis/jedis","slug":"by-is-not-a-valid-zrange-type-argument","errorCode":null,"errorMessage":"${by} is not a valid ZRANGE type argument.","messagePattern":"(.+?) is not a valid ZRANGE type argument\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/params/ZRangeParams.java","lineNumber":60,"sourceCode":"  public static ZRangeParams zrangeParams(long min, long max) {\n    return new ZRangeParams(min, max);\n  }\n\n  public ZRangeParams(double min, double max) {\n    this.by = BYSCORE;\n    this.min = from(min);\n    this.max = from(max);\n  }\n\n  public static ZRangeParams zrangeByScoreParams(double min, double max) {\n    return new ZRangeParams(min, max);\n  }\n\n  private ZRangeParams(Keyword by, Rawable min, Rawable max) {\n    if (by == null || by == BYSCORE || by == BYLEX) {\n      // ok\n    } else {\n      throw new IllegalArgumentException(by.name() + \" is not a valid ZRANGE type argument.\");\n    }\n    this.by = by;\n    this.min = min;\n    this.max = max;\n  }\n\n  public ZRangeParams(Keyword by, String min, String max) {\n    this(by, from(min), from(max));\n  }\n\n  public ZRangeParams(Keyword by, byte[] min, byte[] max) {\n    this(by, from(min), from(max));\n  }\n\n  public static ZRangeParams zrangeByLexParams(String min, String max) {\n    return new ZRangeParams(BYLEX, min, max);\n  }\n","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/params/ZRangeParams.java#L42-L78","documentation":"The private ZRangeParams constructor only accepts ZRANGEBYSCORE (BYSCORE) or ZRANGEBYLEX (BYLEX) as the range type; any other keyword (or a null handled as a bad name) produces this IllegalArgumentException. It protects against constructing ZRangeParams with an unsupported range semantics.","triggerScenarios":"Constructing ZRangeParams via a static factory or reflection path that passes a different Keyword (e.g. BYRANK or a custom Rawable keyword) instead of byScore()/byLex()/byRank() entry points.","commonSituations":"Writing generic param-building code that forwards an arbitrary Keyword into ZRangeParams; misusing internal constructors after an upgrade changed the allowed set; building params manually instead of using zRangeParams helpers.","solutions":["Use the public factories: ZRangeParams.zRangeByScoreParams(min, max), zRangeByLexParams(min, max), or zRangeByRankParams(min, max).","Fix the code that passes a non-BYSCORE/BYLEX keyword into the constructor.","Check the Jedis version's supported ZRANGE argument types if upgrading changed behavior."],"exampleFix":"// before\nZRangeParams params = new ZRangeParams(Keyword.BYRANK, min, max);\n// after\nZRangeParams params = ZRangeParams.zRangeByRankParams(0, -1);","handlingStrategy":"type-guard","validationCode":"if (by != Keyword.BYSCORE && by != Keyword.BYLEX) throw new IllegalArgumentException(\"Use byScore or byLex for ZRangeParams\");","typeGuard":"boolean isAllowedZRangeBy(Keyword by) { return by == Keyword.BYSCORE || by == Keyword.BYLEX; }","tryCatchPattern":"try {\n  return new ZRangeParams(by, min, max);\n} catch (IllegalArgumentException e) {\n  return ZRangeParams.zRangeByRankParams(0, -1);\n}","preventionTips":["Use the public static factories zRangeByScoreParams/zRangeByLexParams/zRangeByRankParams instead of the constructor.","Never forward arbitrary Keyword values into ZRangeParams.","Only BYRANK is reachable via zRangeByRankParams; the private ctor intentionally excludes it."],"tags":["jedis","params","zset","invalid-argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}