{"record":{"id":"530a3c50ba6867b5","repo":"apache/druid","slug":"value-of-infinite-is-not-allowed","errorCode":null,"errorMessage":"Value of Infinite is not allowed!","messagePattern":"Value of Infinite is not allowed!","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/emitter/service/ServiceMetricEvent.java","lineNumber":198,"sourceCode":"        throw new IAE(\"Value of dimension[%s] cannot be null\", dim);\n      }\n\n      userDims.put(dim, value);\n      return this;\n    }\n\n    public Object getDimension(String dim)\n    {\n      return userDims.get(dim);\n    }\n\n    public Builder setMetric(String metric, Number value)\n    {\n      if (Double.isNaN(value.doubleValue())) {\n        throw new ISE(\"Value of NaN is not allowed!\");\n      }\n      if (Double.isInfinite(value.doubleValue())) {\n        throw new ISE(\"Value of Infinite is not allowed!\");\n      }\n\n      this.metric = metric;\n      this.value = value;\n      return this;\n    }\n\n    public Builder setCreatedTime(DateTime createdTime)\n    {\n      this.createdTime = createdTime;\n      return this;\n    }\n\n    @Override\n    public ServiceMetricEvent build(ImmutableMap<String, String> serviceDimensions)\n    {\n      Preconditions.checkNotNull(metric, \"Metric is not set\");\n      Preconditions.checkNotNull(value, \"Value is not set\");","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/emitter/service/ServiceMetricEvent.java#L180-L216","documentation":"ServiceMetricEvent.Builder.setMetric also rejects infinite values (Double.isInfinite) with ISE. Infinite values (from overflow or division by zero) cannot be aggregated correctly downstream, so the builder throws rather than propagating them into the metrics pipeline.","triggerScenarios":"Calling setMetric(name, value) where value.doubleValue() is Double.POSITIVE_INFINITY or NEGATIVE_INFINITY — commonly from double overflow or x/0.0 on doubles.","commonSituations":"Rate/throughput computations dividing by a near-zero elapsed time; cumulative counters overflowing double range; monitors summing unbounded values.","solutions":["Guard the arithmetic: check denominators, cap/round values, or use long arithmetic before converting to double.","Sanitize before emitting: skip or clamp infinite values to a configured max.","Fix the upstream counter/calculation that overflows.","Log the offending metric name and value so the source computation can be fixed."],"exampleFix":"// before\ndouble rate = processed / elapsedSeconds; // elapsedSeconds == 0.0 -> Infinity\nbuilder.setMetric(\"ingest/rate\", rate); // ISE\n// after\ndouble rate = elapsedSeconds > 0 ? processed / elapsedSeconds : 0.0;\nif (!Double.isInfinite(rate) && !Double.isNaN(rate)) {\n  builder.setMetric(\"ingest/rate\", rate);\n}","handlingStrategy":"validation","validationCode":"double v = metricValue.doubleValue();\nif (Double.isInfinite(v)) { v = cap; /* clamp or skip */ }\nbuilder.setMetric(metricName, v);","typeGuard":null,"tryCatchPattern":"try {\n  builder.setMetric(name, value);\n} catch (IllegalStateException e) {\n  log.warn(\"Skipping non-finite metric [%s]\", name);\n}","preventionTips":["Check denominators (elapsed time, count) before computing rates","Use long arithmetic for counters to avoid double overflow","Clamp or skip infinite values at a single shared emission helper"],"tags":["metrics","infinity","validation","illegal-state"],"backgroundTag":"invalid-argument-value","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}