apache/beam · error · IllegalArgumentException
input should not be NaN or infinite.
Error message
input should not be NaN or infinite.
What it means
Histogram addInput rejects input values that are NaN or infinite, since they cannot be placed in any finite bucket and would corrupt the histogram counts. The input is converted to double via ((Number) input).doubleValue() and checked before the binarySearch into the bounds array.
Solutions
- Filter out NaN/infinite values before the transform: Filter.by(x -> Double.isFinite(((Number) x).doubleValue())).
- Fix the upstream math (guard denominators, clamp results) so finite values are produced.
- Sanitize at ingestion: map NaN/Infinity to a sentinel or drop them with a DoFn.
- If Infinity is meaningful, widen bucket bounds and clamp values to the last bound instead of passing raw Infinity.
Example fix
// before
pcollection.apply(Histogram.globally(...));
// after
pcollection.apply(Filter.by(x -> Double.isFinite(((Number) x).doubleValue())))
.apply(Histogram.globally(...)); Defensive patterns
Strategy: validation
Validate before calling
double d = ((Number) value).doubleValue();
if (Double.isNaN(d) || Double.isInfinite(d)) {
value = clampOrDefault(d); // e.g. skip, or clamp to last bound
} Type guard
boolean isFiniteNumber(T v) {
return v instanceof Number && Double.isFinite(((Number) v).doubleValue());
} Try / catch
try {
histogramFn.addInput(accumulator, value);
} catch (IllegalArgumentException e) {
LOG.warn("dropping non-finite histogram input", e);
} Prevention
- Guard divisions (ratios, rates) against zero denominators.
- Sanitize sensor/ingested data where NaN/Infinity encode missing readings.
- Clamp extreme values to the outermost bucket instead of passing Infinity.
When it happens
Trigger: Feeding the Histogram combiner values produced by division by zero, sqrt of a negative number (NaN), overflowing arithmetic, or parsing of 'Infinity'/'NaN' strings; calling addInput(accumulator, Double.NaN) directly.
Common situations: Computing rates/ratios with zero denominators; sensor data with missing readings encoded as NaN/Infinity; deserializing JSON that contains Infinity; averaging empty windows.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- bounds should be in ascending order without duplicates.
- 2xx codes should not be exceptions. Got status code
- ApproximateUnique.PerKey needs an estimation error between…
- AUTO is not supported for writing
- Cannot merge schemas with different numbers of fields…
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/77f2711e4ae43452.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/extensions/combiners/src/main/java/org/apache/beam/sdk/extensions/combiners/Histogram.java:335
ArrayUtils.toPrimitive(bucketBounds.getBounds().toArray(new Double[0])),
bucketBounds.getBoundsInclusivity());
}
@Override
public HistogramAccumulator createAccumulator() {
return new HistogramAccumulator(bounds.length + 1);
}
@Override
public HistogramAccumulator addInput(HistogramAccumulator accumulator, T input)
throws IllegalArgumentException {
if (input == null) {
throw new NullPointerException("input should not be null.");
}
Double inputDoubleValue = ((Number) input).doubleValue();
if (inputDoubleValue.isNaN() || inputDoubleValue.isInfinite()) {
throw new IllegalArgumentException("input should not be NaN or infinite.");
}
int index = Arrays.binarySearch(bounds, inputDoubleValue);
if (index < 0) {
accumulator.counts[-index - 1]++;
} else {
// This means the value is on bound, can be handled based on the bound inclusivity.
if (boundsInclusivity == BoundsInclusivity.LOWER_BOUND_INCLUSIVE_UPPER_BOUND_EXCLUSIVE) {
accumulator.counts[index + 1]++;
} else {
accumulator.counts[index]++;
}
}
return accumulator;
}
@Override
public HistogramAccumulator mergeAccumulators(Iterable<HistogramAccumulator> accumulators) {
Iterator<HistogramAccumulator> iter = accumulators.iterator();View on GitHub (pinned to 12126d8942)