{"record":{"id":"37735c8d671cbe37","repo":"redis/jedis","slug":"block-min-count-must-be-a-positive-integer","errorCode":null,"errorMessage":"BLOCK min_count must be a positive integer","messagePattern":"BLOCK min_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":92,"sourceCode":"   * blocking it always yields an empty reply.\n   */\n  public TSReadParams newSamples() {\n    this.timestamp = DOLLAR;\n    return this;\n  }\n\n  /**\n   * Opt into blocking. Both values are always emitted on the wire inside the {@code BLOCK} group.\n   * @param milliseconds maximum wait, non-negative; {@code 0} means wait indefinitely\n   * @param minCount unblock threshold, positive; the call returns once this many samples qualify\n   * @return this\n   */\n  public TSReadParams block(long milliseconds, int minCount) {\n    if (milliseconds < 0) {\n      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;","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/timeseries/TSReadParams.java#L74-L110","documentation":"TSReadParams.block(long milliseconds, int minCount) requires minCount to be a positive integer: BLOCK's min_count tells the server how many qualifying samples must arrive before unblocking, and 0 or negative values are invalid, so the client throws IllegalArgumentException before sending the command.","triggerScenarios":"Calling TSReadParams.block(1000, 0) or block(1000, -5); default/uninitialized int fields (0) passed straight into block().","commonSituations":"minCount loaded from optional config that defaults to 0 when unset; code that intends to 'skip' the min-count feature but calls the two-arg block() instead of the single-argument variant.","solutions":["Pass a positive minCount (>= 1).","If min-count is not needed, use the block overload that takes only milliseconds (or omit BLOCK entirely) instead of passing 0.","Default optional config to a sane positive value (e.g. 1) when unset."],"exampleFix":"// before\nint minCount = config.getMinCount(); // defaults to 0\nparams.block(1000, minCount); // throws\n// after\nint minCount = Math.max(1, config.getMinCount());\nparams.block(1000, minCount);","handlingStrategy":"validation","validationCode":"if (minCount <= 0) throw new IllegalStateException(\"minCount must be >= 1\");\nparams.block(ms, minCount);","typeGuard":"static boolean validMinCount(int n) { return n > 0; }","tryCatchPattern":"try { params.block(ms, minCount); } catch (IllegalArgumentException e) { log.warn(\"invalid min_count {}, using 1\", minCount); params.block(ms, 1); }","preventionTips":["Default optional min-count config to 1","Use the milliseconds-only block overload when min_count is not needed","Sanity-check config integers at startup"],"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"}