{"record":{"id":"bc0db9d119cf746f","repo":"apache/hadoop","slug":"interval-should-be-positive-value-passed-is","errorCode":null,"errorMessage":"Interval should be positive.  Value passed is: {}","messagePattern":"Interval should be positive\\.  Value passed is: (.+?)","errorType":"exception","errorClass":"MetricsException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MetricsRegistry.java","lineNumber":221,"sourceCode":"    metricsMap.put(info.name(), ret);\n    return ret;\n  }\n\n  /**\n   * Create a mutable metric that estimates quantiles of a stream of values\n   * @param name of the metric\n   * @param desc metric description\n   * @param sampleName of the metric (e.g., \"Ops\")\n   * @param valueName of the metric (e.g., \"Time\" or \"Latency\")\n   * @param interval rollover interval of estimator in seconds\n   * @return a new quantile estimator object\n   * @throws MetricsException if interval is not a positive integer\n   */\n  public synchronized MutableQuantiles newQuantiles(String name, String desc,\n      String sampleName, String valueName, int interval) {\n    checkMetricName(name);\n    if (interval <= 0) {\n      throw new MetricsException(\"Interval should be positive.  Value passed\" +\n          \" is: \" + interval);\n    }\n    MutableQuantiles ret =\n        new MutableQuantiles(name, desc, sampleName, valueName, interval);\n    metricsMap.put(name, ret);\n    return ret;\n  }\n\n  /**\n   * Create a mutable inverse metric that estimates inverse quantiles of a stream of values\n   * @param name of the metric\n   * @param desc metric description\n   * @param sampleName of the metric (e.g., \"Ops\")\n   * @param valueName of the metric (e.g., \"Rate\")\n   * @param interval rollover interval of estimator in seconds\n   * @return a new inverse quantile estimator object\n   * @throws MetricsException if interval is not a positive integer\n   */","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MetricsRegistry.java#L203-L239","documentation":"MetricsRegistry.newQuantiles creates a MutableQuantiles (rolling-window quantile estimator) and requires a positive rollover interval in seconds; interval <= 0 throws MetricsException('Interval should be positive.  Value passed is: <n>') before the estimator is built.","triggerScenarios":"Calling registry.newQuantiles(name, desc, sampleName, valueName, interval) with interval == 0 or negative — typically a config value that was never set and defaulted to 0.","commonSituations":"Quantile interval wired from a configuration property that is missing (parses to 0); copy-paste from newRate-style calls that take no interval; test code passing 0 as a placeholder.","solutions":["Pass a positive rollover interval in seconds (e.g., 60)","Validate or clamp config-sourced intervals before the call (default to a sane positive value)","Fix the configuration property that supplies the interval"],"exampleFix":"// before\nregistry.newQuantiles(\"QueueTime\", \"Queue time\", \"Ops\", \"Time\", intervalSecs); // intervalSecs == 0\n\n// after\nint intervalSecs = conf.getInt(\"my.quantile.interval\", 60);\nregistry.newQuantiles(\"QueueTime\", \"Queue time\", \"Ops\", \"Time\", Math.max(1, intervalSecs));","handlingStrategy":"validation","validationCode":"if (interval <= 0) {\n  throw new IllegalArgumentException(\"quantile interval must be positive, got \" + interval);\n}\nregistry.newQuantiles(\"QueueTime\", \"Queue time\", \"Ops\", \"Time\", interval);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default config-sourced intervals to a positive value (e.g., 60 seconds)","Clamp with Math.max(1, interval) at the boundary","Add a config sanity check that fails fast on non-positive quantile intervals"],"tags":["metrics2","hadoop","quantiles","argument-validation"],"backgroundTag":"non-positive-interval","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}