{"record":{"id":"1bc5bf72a0a44946","repo":"apache/beam","slug":"window-coders-must-be-deterministic","errorCode":null,"errorMessage":"Window coders must be deterministic.","messagePattern":"Window coders must be deterministic\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/windowing/Window.java","lineNumber":186,"sourceCode":"     */\n    FIRE_ALWAYS,\n    /** Only fire the on-time pane if there is new data since the previous firing. */\n    FIRE_IF_NON_EMPTY\n  }\n\n  /**\n   * Creates a {@code Window} {@code PTransform} that uses the given {@link WindowFn} to window the\n   * data.\n   *\n   * <p>The resulting {@code PTransform}'s types have been bound, with both the input and output\n   * being a {@code PCollection<T>}, inferred from the types of the argument {@code WindowFn}. It is\n   * ready to be applied, or further properties can be set on it first.\n   */\n  public static <T> Window<T> into(WindowFn<? super T, ?> fn) {\n    try {\n      fn.windowCoder().verifyDeterministic();\n    } catch (NonDeterministicException e) {\n      throw new IllegalArgumentException(\"Window coders must be deterministic.\", e);\n    }\n    return Window.<T>configure().withWindowFn(fn);\n  }\n\n  /**\n   * Returns a new builder for a {@link Window} transform for setting windowing parameters other\n   * than the windowing function.\n   */\n  public static <T> Window<T> configure() {\n    return new AutoValue_Window.Builder<T>().build();\n  }\n\n  public abstract @Nullable WindowFn<? super T, ?> getWindowFn();\n\n  abstract @Nullable Trigger getTrigger();\n\n  abstract @Nullable AccumulationMode getAccumulationMode();\n","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/windowing/Window.java#L168-L204","documentation":"Window.into requires the target WindowFn's window coder to be deterministic, because Beam shuffles/retries elements and window values must serialize identically each time. If the coder's verifyDeterministic throws NonDeterministicException, Window.into wraps it in an IllegalArgumentException so the failure surfaces at transform construction time.","triggerScenarios":"Calling Window.into(fn) (or Window.configure().withWindowFn(fn)) where fn.windowCoder() declares NonDeterministicException — e.g. a custom WindowFn whose coder encodes unordered sets or object hashes.","commonSituations":"Custom WindowFn development with a hand-rolled coder (e.g. one backed by String.valueOf(double) or HashSet ordering); third-party windowfns with non-deterministic coders; pipelines failing at construction before any data flows.","solutions":["Make the custom window coder deterministic: encode fields in a canonical order with stable encodings","Use Coder.verifyDeterministic to list offending components and fix them (e.g. sort collections before encoding)","Replace non-deterministic components (doubles via bit-pattern, maps, sets) with ordered/deterministic equivalents","If you cannot fix the coder, choose a different WindowFn with a deterministic coder"],"exampleFix":"// before\nclass MyWindowCoder extends CustomCoder<MyWindow> {\n  void encode(MyWindow w, OutputStream out) { new HashSetCoder<>(StringUtf8Coder.of()).encode(w.tags, out); } // non-deterministic\n}\n// after\nvoid encode(MyWindow w, OutputStream out) {\n  List<String> sorted = new ArrayList<>(w.tags);\n  Collections.sort(sorted);\n  ListCoder.of(StringUtf8Coder.of()).encode(sorted, out);\n}","handlingStrategy":"validation","validationCode":"try { fn.windowCoder().verifyDeterministic(); } catch (NonDeterministicException e) { throw new IllegalArgumentException(\"WindowFn \" + fn + \" has non-deterministic coder\", e); }","typeGuard":"boolean hasDeterministicWindowCoder(WindowFn<?,?> fn) { try { fn.windowCoder().verifyDeterministic(); return true; } catch (NonDeterministicException e) { return false; } }","tryCatchPattern":"try { return Window.into(fn); } catch (IllegalArgumentException e) { if (e.getCause() instanceof NonDeterministicException) { LOG.error(\"Fix window coder determinism\", e); } throw e; }","preventionTips":["Always call verifyDeterministic() in custom coder unit tests","Avoid Set/Map coders and hash/toString(double) encodings in window coders","Sort or canonicalize collections before encoding","Derive custom coders from deterministic primitive coders only"],"tags":["java","apache-beam","windowing","coder","determinism"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}