{"record":{"id":"1376ed19e93e2cc3","repo":"apache/beam","slug":"input-should-not-be-null","errorCode":null,"errorMessage":"input should not be null.","messagePattern":"input should not be null\\.","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/combiners/src/main/java/org/apache/beam/sdk/extensions/combiners/Histogram.java","lineNumber":330,"sourceCode":"     * @param bucketBounds the instance of the {@link BucketBounds} class with desired parameters of\n     *     the histogram.\n     */\n    public static <T extends Number> HistogramCombineFn<T> create(BucketBounds bucketBounds) {\n      return new HistogramCombineFn<>(\n          ArrayUtils.toPrimitive(bucketBounds.getBounds().toArray(new Double[0])),\n          bucketBounds.getBoundsInclusivity());\n    }\n\n    @Override\n    public HistogramAccumulator createAccumulator() {\n      return new HistogramAccumulator(bounds.length + 1);\n    }\n\n    @Override\n    public HistogramAccumulator addInput(HistogramAccumulator accumulator, T input)\n        throws IllegalArgumentException {\n      if (input == null) {\n        throw new NullPointerException(\"input should not be null.\");\n      }\n\n      Double inputDoubleValue = ((Number) input).doubleValue();\n      if (inputDoubleValue.isNaN() || inputDoubleValue.isInfinite()) {\n        throw new IllegalArgumentException(\"input should not be NaN or infinite.\");\n      }\n      int index = Arrays.binarySearch(bounds, inputDoubleValue);\n      if (index < 0) {\n        accumulator.counts[-index - 1]++;\n      } else {\n        // This means the value is on bound, can be handled based on the bound inclusivity.\n        if (boundsInclusivity == BoundsInclusivity.LOWER_BOUND_INCLUSIVE_UPPER_BOUND_EXCLUSIVE) {\n          accumulator.counts[index + 1]++;\n        } else {\n          accumulator.counts[index]++;\n        }\n      }\n      return accumulator;","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/combiners/src/main/java/org/apache/beam/sdk/extensions/combiners/Histogram.java#L312-L348","documentation":"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.","triggerScenarios":"Applying a Histogram combine/combineFn transform over a PCollection that contains null elements, or calling addInput(accumulator, null) directly on the combine function.","commonSituations":"Upstream parses/lookups returning null for missing values; Avro/JSON sources with missing fields producing null records; test pipelines feeding null as a sentinel.","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."],"exampleFix":"// before\npcollection.apply(Histogram.globally(...));\n// after\npcollection.apply(Filter.by(x -> x != null)).apply(Histogram.globally(...));","handlingStrategy":"validation","validationCode":"PCollection<T> nonNull = input.apply(\"DropNulls\", Filter.by(v -> v != null));\nnonNull.apply(Histogram.globally(...));","typeGuard":"boolean isUsableInput(T v) { return v != null; }","tryCatchPattern":"try {\n  histogramFn.addInput(accumulator, value);\n} catch (NullPointerException e) {\n  // skip or log the null element\n}","preventionTips":["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."],"tags":["java","null-pointer","histogram","pipeline"],"backgroundTag":"null-argument","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"}