{"record":{"id":"b3902254b8ac9812","repo":"apache/beam","slug":"iterablelikecoder-can-not-guarantee-deterministic-ordering","errorCode":null,"errorMessage":"IterableLikeCoder can not guarantee deterministic ordering.","messagePattern":"IterableLikeCoder can not guarantee deterministic ordering\\.","errorType":"exception","errorClass":"NonDeterministicException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/IterableLikeCoder.java","lineNumber":170,"sourceCode":"      return decodeToIterable(elements, count, inStream);\n    }\n  }\n\n  @Override\n  public List<? extends Coder<?>> getCoderArguments() {\n    return Arrays.asList(elementCoder);\n  }\n\n  /**\n   * {@inheritDoc}\n   *\n   * @throws NonDeterministicException always. Encoding is not deterministic for the general {@link\n   *     Iterable} case, as it depends upon the type of iterable. This may allow two objects to\n   *     compare as equal while the encoding differs.\n   */\n  @Override\n  public void verifyDeterministic() throws NonDeterministicException {\n    throw new NonDeterministicException(\n        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) {","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/IterableLikeCoder.java#L152-L188","documentation":"IterableLikeCoder.verifyDeterministic() always throws NonDeterministicException: for a general Iterable the encoded byte order depends on the iterable's iteration order and concrete type, so two equal objects can encode differently. Deterministic coders are required for grouping and keyed operations.","triggerScenarios":"Using ListCoder/IterableCoder/SetCoder elements (or nested in a KV coder) in GroupByKey, Combine.perKey, stateful processing, or any explicit verifyDeterministic() call when iteration order is not guaranteed.","commonSituations":"Grouping values that are Sets or unordered Iterables; pushing unordered collection data through key-based shuffles.","solutions":["Replace the iterable with a deterministically ordered List (sort elements in a DoFn before grouping).","Use ListCoder with sorted lists instead of SetCoder when order-independent semantics allow it and determinism is required.","Keep deterministic element coders and accept ordering guarantees from the producing transform."],"exampleFix":"// before\nPCollection<KV<String, Set<String>>> pc; // GroupByKey throws on SetCoder\n// after\nPCollection<KV<String, List<String>>> sorted =\n    pc.apply(MapElements.via(kv -> KV.of(kv.getKey(), new ArrayList<>(new TreeSet<>(kv.getValue())))));","handlingStrategy":"fallback","validationCode":"try { coder.verifyDeterministic(); } catch (Coder.NonDeterministicException e) { /* sort or switch to ListCoder */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Sort iterable elements before grouping stages.","Prefer ListCoder with sorted lists over SetCoder for shuffle-heavy pipelines.","Test verifyDeterministic on all coders used in GroupByKey/Combine paths."],"tags":["java","apache-beam","coders","determinism","collections"],"backgroundTag":"unsupported-operation","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"}