{"record":{"id":"bb5e196c1ac28252","repo":"apache/beam","slug":"nondeterministicexception-target-message-e","errorCode":null,"errorMessage":"NonDeterministicException(target, message, e)","messagePattern":"NonDeterministicException\\(target, message, e\\)","errorType":"exception","errorClass":"NonDeterministicException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/Coder.java","lineNumber":201,"sourceCode":"   *   <li>the {@code Coder} always produces a canonical encoding, which is the same for an instance\n   *       of an object even if produced on different computers at different times.\n   * </ul>\n   *\n   * @throws Coder.NonDeterministicException if this coder is not deterministic.\n   */\n  public abstract void verifyDeterministic() throws Coder.NonDeterministicException;\n\n  /**\n   * Verifies all of the provided coders are deterministic. If any are not, throws a {@link\n   * NonDeterministicException} for the {@code target} {@link Coder}.\n   */\n  public static void verifyDeterministic(Coder<?> target, String message, Iterable<Coder<?>> coders)\n      throws NonDeterministicException {\n    for (Coder<?> coder : coders) {\n      try {\n        coder.verifyDeterministic();\n      } catch (NonDeterministicException e) {\n        throw new NonDeterministicException(target, message, e);\n      }\n    }\n  }\n\n  public static <T> long getEncodedElementByteSizeUsingCoder(Coder<T> target, T value)\n      throws Exception {\n    return target.getEncodedElementByteSize(value);\n  }\n\n  /**\n   * Verifies all of the provided coders are deterministic. If any are not, throws a {@link\n   * NonDeterministicException} for the {@code target} {@link Coder}.\n   */\n  public static void verifyDeterministic(Coder<?> target, String message, Coder<?>... coders)\n      throws NonDeterministicException {\n    verifyDeterministic(target, message, Arrays.asList(coders));\n  }\n","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/Coder.java#L183-L219","documentation":"Coder.verifyDeterministic(target, message, coders) aggregates determinism violations from component coders: when any component coder fails its own verifyDeterministic, it throws NonDeterministicException against the target with the given message. It means a composite coder is non-deterministic because one of its component coders is.","triggerScenarios":"Calling verifyDeterministic on a composite coder (e.g. a custom coder for a struct/Pair) whose component list includes a known non-deterministic coder such as DoubleCoder, BigDecimalCoder, or a coder for unordered collections.","commonSituations":"Using a struct with a double/float/BigDecimal field as a GroupByKey key, pipeline-construction key validation rejecting a coder, Beam GBK setup failing on non-deterministic keys.","solutions":["Replace the non-deterministic component with a deterministic encoding, e.g. encode doubles via Double.toString or a scaled long","Use a deterministic wrapper coder for the offending type","Change the GBK key type to one with a deterministic coder (string, long, byte[] with ByteArrayCoder)","Remove the offending field from the key"],"exampleFix":"// before\nCoder<MyKey> coder = new MyKeyCoder(DoubleCoder.of(), StringUtf8Coder.of());\n// after\nCoder<MyKey> coder = new MyKeyCoder(\n    StringUtf8Coder.of(), // double encoded via Double.toString -> deterministic\n    StringUtf8Coder.of());","handlingStrategy":"validation","validationCode":"try { coder.verifyDeterministic(); } catch (Coder.NonDeterministicException e) { /* fix coder before launching pipeline */ }","typeGuard":null,"tryCatchPattern":"try { Coder.verifyDeterministic(targetCoder, \"key coder must be deterministic\", componentCoders); } catch (Coder.NonDeterministicException e) { throw new IllegalArgumentException(\"Use a deterministic key encoding\", e); }","preventionTips":["Run verifyDeterministic in unit tests for every custom coder used as a GBK key","Avoid float/double/map types in keys or canonicalize them via a deterministic string form"],"tags":["java","beam","coders","determinism"],"backgroundTag":"non-deterministic-coder","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"}