{"record":{"id":"d017e16ba3ccfc51","repo":"apache/beam","slug":"the-bound-has-overflown-double-type","errorCode":null,"errorMessage":"the bound has overflown double type.","messagePattern":"the bound has overflown double type\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/combiners/src/main/java/org/apache/beam/sdk/extensions/combiners/Histogram.java","lineNumber":183,"sourceCode":"    public static BucketBounds exponential(\n        double scale,\n        double growthFactor,\n        int numBoundedBuckets,\n        BoundsInclusivity boundsInclusivity) {\n      checkArgument(scale > 0.0, \"scale should be positive.\");\n      checkArgument(growthFactor > 1.0, \"growth factor should be greater than 1.0.\");\n      checkArgument(\n          numBoundedBuckets > 0, \"number of bounded buckets should be greater than zero.\");\n      checkArgument(\n          numBoundedBuckets <= Integer.MAX_VALUE - 2,\n          \"number of bounded buckets should be less than max value of integer.\");\n\n      ImmutableList.Builder<Double> boundsCalculated = new ImmutableList.Builder<>();\n      // The number of bounds is equal to the numBoundedBuckets + 1.\n      for (int i = 0; i <= numBoundedBuckets; i++) {\n        double bound = scale * Math.pow(growthFactor, i);\n        if (Double.isInfinite(bound)) {\n          throw new IllegalArgumentException(\"the bound has overflown double type.\");\n        }\n        boundsCalculated.add(bound);\n      }\n\n      return new AutoValue_Histogram_BucketBounds(boundsCalculated.build(), boundsInclusivity);\n    }\n\n    /**\n     * Like {@link #exponential(double, double, int, BoundsInclusivity)}, but sets\n     * BoundsInclusivity.LOWER_BOUND_INCLUSIVE_UPPER_BOUND_EXCLUSIVE value for the boundsInclusivity\n     * parameter.\n     */\n    public static BucketBounds exponential(\n        double scale, double growthFactor, int numBoundedBuckets) {\n      return exponential(\n          scale,\n          growthFactor,\n          numBoundedBuckets,","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/combiners/src/main/java/org/apache/beam/sdk/extensions/combiners/Histogram.java#L165-L201","documentation":"Histogram.BucketBounds.exponential(scale, growthFactor, numBoundedBuckets) computes bucket bounds as scale * growthFactor^i for i in [0, numBoundedBuckets]. If any computed bound exceeds Double.MAX_VALUE it becomes infinite, and the method throws this IllegalArgumentException rather than returning a histogram with infinite bounds, because such bounds cannot be represented as finite doubles.","triggerScenarios":"Calling BucketBounds.exponential with scale * growthFactor^numBoundedBuckets > Double.MAX_VALUE (~1.8e308) — e.g., scale=1e10, growthFactor=100, numBoundedBuckets=200, or any large growthFactor with enough buckets.","commonSituations":"Configuring an exponential histogram for a very wide value range with a large growth factor and many buckets; copy-pasted parameters tuned for a different data scale; computing bounds programmatically without checking magnitude.","solutions":["Reduce numBoundedBuckets or growthFactor so scale * growthFactor^numBoundedBuckets stays below ~1.8e308.","Reduce scale if it is larger than the smallest value you actually need to bucket.","Compute Math.log(growthFactor) bounds check up front: if Math.log10(scale) + numBoundedBuckets*Math.log10(growthFactor) > ~308, pick smaller parameters.","Catch IllegalArgumentException and fall back to linear bounds or fewer buckets."],"exampleFix":"// before\nHistogram.BucketBounds bounds =\n    BucketBounds.exponential(1e10, 100, 200); // 1e10 * 100^200 overflows double\n\n// after\nHistogram.BucketBounds bounds =\n    BucketBounds.exponential(1e10, 10, 30); // max bound 1e10 * 10^30 = 1e40, safe","handlingStrategy":"validation","validationCode":"double maxBound = scale * Math.pow(growthFactor, numBoundedBuckets);\nif (Double.isInfinite(maxBound)) {\n  throw new IllegalArgumentException(\n      \"scale*growthFactor^numBoundedBuckets overflows double; reduce parameters\");\n}\nHistogram.BucketBounds bounds = BucketBounds.exponential(scale, growthFactor, numBoundedBuckets);","typeGuard":null,"tryCatchPattern":"try {\n  bounds = BucketBounds.exponential(scale, growthFactor, numBuckets);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"overflown double\")) {\n    bounds = BucketBounds.exponential(scale, Math.sqrt(growthFactor), numBuckets); // fallback\n  } else { throw e; }\n}","preventionTips":["Check log10(scale) + numBoundedBuckets * log10(growthFactor) <= 308 before calling.","Prefer a growthFactor like 2 or 10 with a moderate bucket count over huge factors.","Unit-test histogram configuration with the largest expected input values."],"tags":["beam","histogram","double-overflow","combiner","illegal-argument"],"backgroundTag":"value-out-of-range","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}