{"record":{"id":"e23a88d51159e256","repo":"apache/beam","slug":"width-should-be-greater-than-zero-f","errorCode":null,"errorMessage":"width should be greater than zero: %f","messagePattern":"width should be greater than zero: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/util/HistogramData.java","lineNumber":654,"sourceCode":"    }\n\n    @Memoized\n    @Override\n    public abstract int hashCode();\n  }\n\n  @AutoValue\n  public abstract static class LinearBuckets implements BucketType {\n    public abstract double getStart();\n\n    public abstract double getWidth();\n\n    @Override\n    public abstract int getNumBuckets();\n\n    public static LinearBuckets of(double start, double width, int numBuckets) {\n      if (width <= 0) {\n        throw new IllegalArgumentException(\n            String.format(\"width should be greater than zero: %f\", width));\n      }\n      if (numBuckets <= 0) {\n        throw new IllegalArgumentException(\n            String.format(\"numBuckets should be greater than zero: %d\", numBuckets));\n      }\n      return new AutoValue_HistogramData_LinearBuckets(start, width, numBuckets);\n    }\n\n    @Override\n    public int getBucketIndex(double value) {\n      return DoubleMath.roundToInt((value - getStart()) / getWidth(), RoundingMode.FLOOR);\n    }\n\n    @Override\n    public double getBucketSize(int index) {\n      return getWidth();\n    }","sourceCodeStart":636,"sourceCodeEnd":672,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/util/HistogramData.java#L636-L672","documentation":"LinearBuckets.of(start, width, numBuckets) requires a strictly positive bucket width. A zero or negative width makes the linear histogram bucketing undefined (every value would map to an invalid bucket), so an IllegalArgumentException with this message is thrown.","triggerScenarios":"Calling HistogramData.LinearBuckets.of(start, width, numBuckets) with width <= 0, e.g. width computed as (max - min)/numBuckets where max == min, or a negative user-supplied width.","commonSituations":"Deriving width from constant data (range of 0); config files where width defaults to 0; sign errors when computing width from differences.","solutions":["Ensure width > 0 before calling of(); guard or throw a clearer application-level error","If width is derived from data range, fall back to a sensible default when max == min","Validate histogram configuration at construction time of your job options"],"exampleFix":"// before\ndouble width = (max - min) / numBuckets; // 0 when max == min\nLinearBuckets.of(min, width, numBuckets);\n// after\ndouble width = Math.max((max - min) / numBuckets, 1.0);\nLinearBuckets.of(min, width, numBuckets);","handlingStrategy":"validation","validationCode":"if (width <= 0) {\n  throw new IllegalArgumentException(\"Bucket width must be positive, got: \" + width);\n}","typeGuard":null,"tryCatchPattern":"try {\n  buckets = LinearBuckets.of(start, width, numBuckets);\n} catch (IllegalArgumentException e) {\n  throw new IllegalArgumentException(\"Invalid linear bucket width: \" + width, e);\n}","preventionTips":["Guard derived widths (e.g. (max-min)/n) against zero/negative ranges","Validate width > 0 in user-facing config parsing"],"tags":["java","histogram","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}