apache/beam · error · NullPointerException
input should not be null.
Error message
input should not be null.
What it means
The Histogram combiner's addInput method requires a non-null input element. Because the combiner accepts generic T values and casts them to Number, a null input would otherwise cause a less clear NullPointerException at the cast site, so an explicit NPE with the message 'input should not be null.' is thrown.
Solutions
- Filter out null elements before the Histogram transform: apply(ParDo) or Filter.of(x -> x != null).
- Replace nulls with a default value or NaN-handling strategy upstream.
- Fix the source (e.g. set nullable=false in the schema) so nulls never enter the pipeline.
Example fix
// before pcollection.apply(Histogram.globally(...)); // after pcollection.apply(Filter.by(x -> x != null)).apply(Histogram.globally(...));
Defensive patterns
Strategy: validation
Validate before calling
PCollection<T> nonNull = input.apply("DropNulls", Filter.by(v -> v != null));
nonNull.apply(Histogram.globally(...)); Type guard
boolean isUsableInput(T v) { return v != null; } Try / catch
try {
histogramFn.addInput(accumulator, value);
} catch (NullPointerException e) {
// skip or log the null element
} Prevention
- Filter nulls immediately after source reads (Avro/JSON fields are often nullable).
- Make source schemas non-nullable for histogram input fields.
- Never use null as a sentinel value in pipeline data.
When it happens
Trigger: Applying a Histogram combine/combineFn transform over a PCollection that contains null elements, or calling addInput(accumulator, null) directly on the combine function.
Common situations: Upstream parses/lookups returning null for missing values; Avro/JSON sources with missing fields producing null records; test pipelines feeding null as a sentinel.
Related errors
- bounds should be in ascending order without duplicates.
- cannot encode a null Integer
- cannot encode a null
- cannot encode a null String
- cannot encode a null ValueKind
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/1376ed19e93e2cc3.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/java/extensions/combiners/src/main/java/org/apache/beam/sdk/extensions/combiners/Histogram.java:330
* @param bucketBounds the instance of the {@link BucketBounds} class with desired parameters of
* the histogram.
*/
public static <T extends Number> HistogramCombineFn<T> create(BucketBounds bucketBounds) {
return new HistogramCombineFn<>(
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;View on GitHub (pinned to 12126d8942)