{"record":{"id":"307ae2cddb9fb2aa","repo":"redis/jedis","slug":"argrepparams-must-be-created-via-unbounded-rang","errorCode":null,"errorMessage":"ArgrepParams must be created via unbounded(), range(), from() or to()","messagePattern":"ArgrepParams must be created via unbounded\\(\\), range\\(\\), from\\(\\) or to\\(\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/params/ArgrepParams.java","lineNumber":254,"sourceCode":"   */\n  public ArgrepParams limit(long limit) {\n    this.limit = limit;\n    return this;\n  }\n\n  /**\n   * Perform all predicate comparisons case-insensitively.\n   * @return this {@link ArgrepParams}\n   */\n  public ArgrepParams nocase() {\n    this.nocase = true;\n    return this;\n  }\n\n  @Override\n  public void addParams(CommandArguments args) {\n    if (startRaw == null || endRaw == null) {\n      throw new IllegalStateException(\n          \"ArgrepParams must be created via unbounded(), range(), from() or to()\");\n    }\n    args.add(startRaw).add(endRaw);\n    for (Predicate p : predicates) {\n      args.add(p.type.keyword).add(p.value);\n    }\n    if (combinator != null) {\n      args.add(combinator);\n    }\n    if (limit != null) {\n      args.add(Keyword.LIMIT).add(limit);\n    }\n    if (nocase) {\n      args.add(Keyword.NOCASE);\n    }\n  }\n\n  private static byte[] encode(String s) {","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/params/ArgrepParams.java#L236-L272","documentation":"ArgrepParams.addParams serializes the parameter object into command arguments, but the start/end bounds must first be established via one of the factory methods unbounded(), range(), from() or to(). If startRaw or endRaw is null, the object was built without any of these, and an IllegalStateException is thrown because the wire format cannot be produced without the bounds segment.","triggerScenarios":"Constructing ArgrepParams directly (e.g. new ArgrepParams() or via a builder) and passing it to an ARGREP-based command without ever calling unbounded(), range(), from(), or to(); asserting serialization in tests before setting bounds.","commonSituations":"Copy-pasting param setup from another command type that has no mandatory bounds; refactoring that removed the bounds call; writing unit tests that serialize a half-initialized params object.","solutions":["Always initialize bounds before use: call unbounded() for a full range, or range(a,b)/from(a)/to(b) for bounded forms.","Use the static factory entry points of ArgrepParams rather than raw construction so the object starts in a valid state.","In tests, call the factory methods before invoking addParams/serialization."],"exampleFix":"// before\nArgrepParams params = new ArgrepParams();\nparams.predicate(Predicate.equal(\"foo\")); // no bounds -> IllegalStateException on serialization\n// after\nArgrepParams params = ArgrepParams.unbounded()\n    .predicate(Predicate.equal(\"foo\")); // or ArgrepParams.range(0, 100)","handlingStrategy":"validation","validationCode":"if (params instanceof ArgrepParams) {\n  // bounds must be set via factory methods before serialization\n  assertBuiltViaFactory(params);\n}","typeGuard":"boolean hasBounds(ArgrepParams p) { return p != null; } // only instances from unbounded/range/from/to are valid","tryCatchPattern":"try {\n  args = command.getCommandArguments();\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"ArgrepParams\")) {\n    params = ArgrepParams.unbounded(); // rebuild with bounds\n  } else throw e;\n}","preventionTips":["Create ArgrepParams only through unbounded(), range(), from(), or to().","Never pass a freshly constructed params object to commands.","Serialize params in tests to catch uninitialized state early."],"tags":["params","illegal-state","argrep","misuse"],"backgroundTag":"internal-invariant-violation","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"}