{"record":{"id":"6b8c4e3485128246","repo":"apache/hadoop","slug":"parameter-0-1-must-be-greater-than-zero","errorCode":null,"errorMessage":"parameter [{0}] = [{1}] must be greater than zero","messagePattern":"parameter \\[(.+?)\\] = \\[(.+?)\\] must be greater than zero","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/util/Check.java","lineNumber":164,"sourceCode":"   * @throws IllegalArgumentException if the integer is zero or less.\n   */\n  public static int gt0(int value, String name) {\n    return (int) gt0((long) value, name);\n  }\n\n  /**\n   * Verifies an long is greater than zero.\n   *\n   * @param value long value.\n   * @param name the name to use in the exception message.\n   *\n   * @return the value.\n   *\n   * @throws IllegalArgumentException if the long is zero or less.\n   */\n  public static long gt0(long value, String name) {\n    if (value <= 0) {\n      throw new IllegalArgumentException(\n        MessageFormat.format(\"parameter [{0}] = [{1}] must be greater than zero\", name, value));\n    }\n    return value;\n  }\n\n  /**\n   * Verifies an integer is greater or equal to zero.\n   *\n   * @param value integer value.\n   * @param name the name to use in the exception message.\n   *\n   * @return the value.\n   *\n   * @throws IllegalArgumentException if the integer is greater or equal to zero.\n   */\n  public static int ge0(int value, String name) {\n    return (int) ge0((long) value, name);\n  }","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/util/Check.java#L146-L182","documentation":"Check.gt0(long value, String name) (Check.java:162) throws this IllegalArgumentException when value <= 0: the number must be strictly positive. It is a precondition helper of the httpfs lib framework for sizes, ports, timeouts, and similar counts; the int overload delegates to the long one, so the same error fires for non-positive ints.","triggerScenarios":"Check.gt0(0, \"port\") or Check.gt0(-1, \"buffer.size\"), typically because a backing config property was unset and the code passed its 0/-1 sentinel into the check instead of a real default.","commonSituations":"An optional property defaulting to 0; -1 used as a 'not configured' sentinel reaching the validator; arithmetic that legitimately produces 0 (a count of items) but flows into a strictly-positive precondition.","solutions":["Set the source configuration property to a positive value.","Replace the 0/-1 'unset' sentinel with a real positive default at the conf.get call site.","If zero is a valid state in your flow, use Check.ge0 instead of gt0.","Validate the value where it is loaded (fail fast with the property name), not deep in call stacks."],"exampleFix":"// before\nlong port = conf.getLong(\"service.port\", 0); // unset -> 0\nCheck.gt0(port, \"service.port\"); // throws: must be greater than zero\n\n// after\nlong port = conf.getLong(\"service.port\", 14000); // positive default\nCheck.gt0(port, \"service.port\"); // ok","handlingStrategy":"validation","validationCode":"long port = conf.getLong(\"service.port\", 0);\nif (port <= 0) {\n  throw new ConfigurationException(\"service.port must be > 0, got \" + port);\n}","typeGuard":"static boolean isPositive(long v) { return v > 0; }","tryCatchPattern":"try {\n  Check.gt0(timeout, \"http.timeout\");\n} catch (IllegalArgumentException ex) {\n  throw new ConfigurationException(\"Invalid config value: \" + ex.getMessage(), ex);\n}","preventionTips":["Never use 0/-1 as 'unset' for strictly-positive fields; use a real positive default in conf.get*.","Validate numeric config once at load time, not per request.","Test 0 and -1 explicitly in config validation tests."],"tags":["java","hadoop","httpfs","validation","numeric"],"backgroundTag":"value-must-be-positive","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}