{"record":{"id":"5c27140faeb9197b","repo":"redis/jedis","slug":"block-milliseconds-must-be-a-non-negative-integer","errorCode":null,"errorMessage":"BLOCK milliseconds must be a non-negative integer","messagePattern":"BLOCK milliseconds must be a non-negative integer","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/timeseries/TSReadParams.java","lineNumber":89,"sourceCode":"  /**\n   * Cursor sentinel {@code $}: the latest sample's timestamp + 1, so only samples added after the\n   * command is received qualify. Meaningful only together with {@link #block(long, int)}; without\n   * 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\");","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/timeseries/TSReadParams.java#L71-L107","documentation":"TSReadParams.block(long milliseconds, int minCount) requires a non-negative BLOCK duration because Redis TS.MRANGE's BLOCK argument accepts only unsigned millisecond values; a negative value is meaningless and would produce a server error, so the client throws IllegalArgumentException immediately. 0 is allowed and means wait indefinitely.","triggerScenarios":"Calling TSReadParams.block(-1, 10), or computing the timeout as remaining-time (e.g. deadline - System.currentTimeMillis()) that has already gone negative.","commonSituations":"Timeout values derived from a deadline that expired before the call; configuration mistakes where the timeout was entered as a negative sentinel to mean 'no wait'.","solutions":["Pass milliseconds >= 0; use 0 for indefinite blocking.","Clamp computed deadlines: long ms = Math.max(0, deadline - System.currentTimeMillis());","If 'do not wait' is intended, drop the block(...) call entirely rather than passing a negative value."],"exampleFix":"// before\nlong ms = deadline - System.currentTimeMillis();\nparams.block(ms, 5); // throws if deadline passed\n// after\nlong ms = Math.max(0, deadline - System.currentTimeMillis());\nparams.block(ms, 5);","handlingStrategy":"validation","validationCode":"long ms = deadline - System.currentTimeMillis();\nif (ms < 0) ms = 0; // or skip block()\nparams.block(ms, minCount);","typeGuard":"static boolean validBlockMs(long ms) { return ms >= 0; }","tryCatchPattern":"try { params.block(ms, minCount); } catch (IllegalArgumentException e) { params.block(0, minCount); }","preventionTips":["Clamp deadline-derived timeouts with Math.max(0, ...)","Use 0 for indefinite rather than negative sentinels","Validate timeout config values at load time"],"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"}