{"record":{"id":"4bc71c3007ccc82f","repo":"apache/beam","slug":"cannot-encode-a-null-iterable","errorCode":null,"errorMessage":"cannot encode a null Iterable","messagePattern":"cannot encode a null Iterable","errorType":"exception","errorClass":"CoderException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/IterableLikeCoder.java","lineNumber":189,"sourceCode":"        this, \"IterableLikeCoder can not guarantee deterministic ordering.\");\n  }\n\n  /**\n   * {@inheritDoc}\n   *\n   * @return {@code true} if the iterable is of a known class that supports lazy counting of byte\n   *     size, since that requires minimal extra computation.\n   */\n  @Override\n  public boolean isRegisterByteSizeObserverCheap(IterableT iterable) {\n    return iterable instanceof ElementByteSizeObservableIterable;\n  }\n\n  @Override\n  public void registerByteSizeObserver(IterableT iterable, ElementByteSizeObserver observer)\n      throws Exception {\n    if (iterable == null) {\n      throw new CoderException(\"cannot encode a null Iterable\");\n    }\n\n    if (iterable instanceof ElementByteSizeObservableIterable) {\n      observer.setLazy();\n      ElementByteSizeObservableIterable<?, ?> observableIterable =\n          (ElementByteSizeObservableIterable<?, ?>) iterable;\n      observableIterable.addObserver(\n          new IteratorObserver(observer, iterable instanceof Collection));\n    } else {\n      if (iterable instanceof Collection) {\n        // We can know the size of the Iterable.  Use an encoding with a\n        // leading size field, followed by that many elements.\n        Collection<T> collection = (Collection<T>) iterable;\n        observer.update(4L);\n        for (T elem : collection) {\n          elementCoder.registerByteSizeObserver(elem, observer);\n        }\n      } else {","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/IterableLikeCoder.java#L171-L207","documentation":"registerByteSizeObserver on IterableLikeCoder was called with a null iterable while estimating encoded sizes (e.g. for GroupByKey output size estimation). The coder cannot observe element sizes of an absent iterable, so the null IterableT argument is rejected; null must instead be represented by a NullableCoder wrapper.","triggerScenarios":"Calling coder.registerByteSizeObserver(null, observer) on a ListCoder/IterableCoder/SetCoder, or Beam's size estimation running over a PCollection whose iterable elements include nulls.","commonSituations":"Sized side inputs containing null collections; pipelines where list-valued fields are optional and unsanitized.","solutions":["Substitute Collections.emptyList() for null collections upstream.","Wrap with NullableCoder.of(...) so nulls have an encoded size.","Filter null collection elements before the size-observed stage."],"exampleFix":"// before\ncoder.registerByteSizeObserver(null, observer); // CoderException\n// after\ncoder.registerByteSizeObserver(items == null ? Collections.emptyList() : items, observer);","handlingStrategy":"validation","validationCode":"if (iterable != null) { coder.registerByteSizeObserver(iterable, observer); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize null collections to empty lists before size estimation stages.","Apply NullableCoder when optional collections are required.","Keep collection-typed fields non-null by construction in element classes."],"tags":["java","apache-beam","coders","null","collections"],"backgroundTag":"null-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}