{"record":{"id":"0051f7c12d056e21","repo":"redis/jedis","slug":"max-count-must-be-a-positive-integer","errorCode":null,"errorMessage":"MAX_COUNT must be a positive integer","messagePattern":"MAX_COUNT must be a positive integer","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/timeseries/TSReadParams.java","lineNumber":107,"sourceCode":"      throw new IllegalArgumentException(\"BLOCK milliseconds must be a non-negative integer\");\n    }\n    if (minCount <= 0) {\n      throw new IllegalArgumentException(\"BLOCK min_count must be a positive integer\");\n    }\n    this.blockMilliseconds = milliseconds;\n    this.blockMinCount = minCount;\n    return this;\n  }\n\n  /**\n   * Reply cap. When more samples qualify than {@code maxCount}, the oldest {@code maxCount} are\n   * returned so callers can page forward. Omitted means unlimited.\n   * @param maxCount positive integer\n   * @return this\n   */\n  public TSReadParams maxCount(int maxCount) {\n    if (maxCount <= 0) {\n      throw new IllegalArgumentException(\"MAX_COUNT must be a positive integer\");\n    }\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) {","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/timeseries/TSReadParams.java#L89-L125","documentation":"TSReadParams.maxCount(int maxCount) validates that MAX_COUNT is a positive integer before adding it to the TS.MREAD/TS.MRANGE command. MAX_COUNT limits how many samples per series are returned; 0 or negative values are invalid per the RedisTimeSeries protocol, so the client throws IllegalArgumentException.","triggerScenarios":"Calling TSReadParams.maxCount(0) or maxCount(-1); page-size fields defaulting to 0 from uninitialized config; computed limits like total - fetched that hit 0.","commonSituations":"Pagination code where a 'zero more items' condition accidentally calls maxCount(0) instead of stopping pagination; optional config defaults.","solutions":["Pass a positive integer (>= 1) for the page size.","Stop paginating before calling the command when the remaining count reaches 0.","Apply Math.max(1, requested) at the config boundary if a minimum page size is acceptable."],"exampleFix":"// before\nint remaining = total - fetched;\nparams.maxCount(remaining); // throws when remaining == 0\n// after\nint remaining = total - fetched;\nif (remaining <= 0) return; // done paging\nparams.maxCount(remaining);","handlingStrategy":"validation","validationCode":"int remaining = total - fetched;\nif (remaining > 0) params.maxCount(remaining); else return;","typeGuard":"static boolean validMaxCount(int n) { return n > 0; }","tryCatchPattern":"try { params.maxCount(n); } catch (IllegalArgumentException e) { params.maxCount(1); }","preventionTips":["Stop pagination before requesting 0 items","Clamp page-size config to >= 1","Keep page-size defaults positive in config classes"],"tags":["java","validation","timeseries","argument-out-of-range"],"backgroundTag":"argument-out-of-range","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"}