{"record":{"id":"1efe176384838e46","repo":"apache/hadoop","slug":"maxretries-maxretries-0","errorCode":null,"errorMessage":"maxRetries = ${maxRetries} < 0","messagePattern":"maxRetries = (.+?) < 0","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java","lineNumber":272,"sourceCode":"  \n  /**\n   * Retry up to maxRetries.\n   * The actual sleep time of the n-th retry is f(n, sleepTime),\n   * where f is a function provided by the subclass implementation.\n   *\n   * The object of the subclasses should be immutable;\n   * otherwise, the subclass must override hashCode(), equals(..) and toString().\n   */\n  static abstract class RetryLimited implements RetryPolicy {\n    final int maxRetries;\n    final long sleepTime;\n    final TimeUnit timeUnit;\n    \n    private String myString;\n\n    RetryLimited(int maxRetries, long sleepTime, TimeUnit timeUnit) {\n      if (maxRetries < 0) {\n        throw new IllegalArgumentException(\"maxRetries = \" + maxRetries+\" < 0\");\n      }\n      if (sleepTime < 0) {\n        throw new IllegalArgumentException(\"sleepTime = \" + sleepTime + \" < 0\");\n      }\n\n      this.maxRetries = maxRetries;\n      this.sleepTime = sleepTime;\n      this.timeUnit = timeUnit;\n    }\n\n    @Override\n    public RetryAction shouldRetry(Exception e, int retries, int failovers,\n        boolean isIdempotentOrAtMostOnce) throws Exception {\n      if (retries >= maxRetries) {\n        return new RetryAction(RetryAction.RetryDecision.FAIL, 0 , getReason());\n      }\n      return new RetryAction(RetryAction.RetryDecision.RETRY,\n          timeUnit.toMillis(calculateSleepTime(retries)), getReason());","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/retry/RetryPolicies.java#L254-L290","documentation":"RetryLimited is the base of Hadoop's bounded retry policies (RetryUpToMaximumCountWithFixedSleep and friends). Its constructor fails fast when maxRetries < 0: a negative retry count is never a valid policy, only a programming or configuration error, and the exception names the offending value.","triggerScenarios":"Constructing any RetryLimited-based policy (e.g. RetryPolicies.retryUpToMaximumCount) with a negative count — typically a parsed config value the user set negative, or arithmetic like retries - 1 dipping below zero.","commonSituations":"Site.xml with a negative retry property; policy values computed from capacity math without a floor; arguments passed in the wrong order (sleepTime where maxRetries goes), which the next guard may also catch.","solutions":["Find the value's origin: log the parsed config property before constructing the policy.","Validate/clamp user-supplied retry counts at the config layer and reject negatives with the property name in the message.","Check the argument order against the factory signature (maxRetries, sleepTime, timeUnit) — swapped args are a classic cause."],"exampleFix":"// before\nRetryPolicy p = RetryPolicies.retryUpToMaximumCount(-1, 1, TimeUnit.SECONDS);\n\n// after\nint retries = Math.max(0, conf.getInt(\"my.retries\", 3));\nRetryPolicy p = RetryPolicies.retryUpToMaximumCount(retries, 1, TimeUnit.SECONDS);","handlingStrategy":"validation","validationCode":"int maxRetries = conf.getInt(\"my.retries\", 3);\nif (maxRetries < 0) {\n  throw new IllegalArgumentException(\n      \"my.retries must be >= 0, got \" + maxRetries);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate retry knobs at startup with the property name in the error message.","Never compute retry counts by subtraction without a floor of 0.","Unit-test policy construction at boundaries (-1, 0, Integer.MAX_VALUE)."],"tags":["retry-policy","configuration","illegal-argument","hadoop-common"],"backgroundTag":"invalid-config-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}