{"record":{"id":"3a072dc2d1942806","repo":"redis/jedis","slug":"block-min-count-must-be-max-count","errorCode":null,"errorMessage":"BLOCK min_count must be <= MAX_COUNT","messagePattern":"BLOCK min_count must be <= MAX_COUNT","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/timeseries/TSReadParams.java","lineNumber":126,"sourceCode":"    }\n    this.maxCount = maxCount;\n    return this;\n  }\n\n  /**\n   * @return true when the {@code BLOCK} group is present, so the command must be issued with\n   *         blocking-command connection handling\n   */\n  public boolean isBlocking() {\n    return blockMilliseconds != null;\n  }\n\n  @Override\n  public void addParams(CommandArguments args) {\n\n    // min_count <= max_count is required by the server when both are set; validate locally too.\n    if (blockMinCount != null && maxCount != null && blockMinCount > maxCount) {\n      throw new IllegalArgumentException(\"BLOCK min_count must be <= MAX_COUNT\");\n    }\n\n    args.add(timestamp);\n\n    if (blockMilliseconds != null) {\n      args.add(BLOCK).add(toByteArray(blockMilliseconds)).add(toByteArray(blockMinCount));\n    }\n\n    if (maxCount != null) {\n      args.add(MAX_COUNT).add(toByteArray(maxCount));\n    }\n  }\n\n  @Override\n  public boolean equals(Object o) {\n    if (this == o) {\n      return true;\n    }","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/timeseries/TSReadParams.java#L108-L144","documentation":"TSReadParams.addParams(CommandArguments) performs a cross-field consistency check: RedisTimeSeries requires BLOCK's min_count to be <= MAX_COUNT when both are set, and the client enforces it locally. If min_count exceeds max_count the command could never return enough samples to satisfy min_count, so the library throws IllegalArgumentException instead of sending a doomed request.","triggerScenarios":"Chaining TSReadParams.block(1000, 50).maxCount(10) (or setting the fields in any order) so minCount=50 > maxCount=10; mutating maxCount on a shared params object after block() was configured.","commonSituations":"Independent config values (block threshold and page size) sourced from different settings that no one reconciled; reuse of a mutable TSReadParams across calls where one field was updated but not the other.","solutions":["Ensure minCount <= maxCount whenever both are set, e.g. block(1000, Math.min(minCount, pageSize)).","Reorder configuration so maxCount is validated first and minCount clamped to it.","If min_count semantics matter more than the page limit, raise maxCount to at least minCount."],"exampleFix":"// before\nparams.block(1000, 50).maxCount(10); // throws at command build\n// after\nint minCount = 50, maxCount = 10;\nparams.block(1000, Math.min(minCount, maxCount)).maxCount(maxCount);","handlingStrategy":"validation","validationCode":"if (minCount > maxCount) {\n  minCount = maxCount; // clamp before building params\n}\nparams.block(blockMs, minCount).maxCount(maxCount);","typeGuard":null,"tryCatchPattern":"try { jedis.tsMRange(params); } catch (IllegalArgumentException e) { log.error(\"min_count > max_count in TSReadParams\", e); throw e; }","preventionTips":["Set block() and maxCount() together from one reconciled config","Clamp minCount to maxCount at the config boundary","Avoid mutating shared TSReadParams instances across calls"],"tags":["java","validation","timeseries","conflicting-options"],"backgroundTag":"conflicting-config-options","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"}