{"record":{"id":"94dffae15a5513c7","repo":"apache/beam","slug":"error-deserializing-via-coder","errorCode":null,"errorMessage":"Error deserializing via Coder","messagePattern":"Error deserializing via Coder","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/testing/SerializableMatchers.java","lineNumber":797,"sourceCode":"    private Coder<T> coder;\n\n    public SerializableViaCoder(Coder<T> coder, T value) {\n      this.coder = coder;\n      this.value = value;\n      try {\n        this.encodedValue = CoderUtils.encodeToByteArray(coder, value);\n      } catch (CoderException exc) {\n        throw new RuntimeException(\"Error serializing via Coder\", exc);\n      }\n    }\n\n    @Override\n    public T get() {\n      if (value == null) {\n        try {\n          value = CoderUtils.decodeFromByteArray(coder, encodedValue);\n        } catch (CoderException exc) {\n          throw new RuntimeException(\"Error deserializing via Coder\", exc);\n        }\n      }\n      return value;\n    }\n  }\n\n  /**\n   * Wraps any array with values that can be encoded via a {@link Coder} to make it {@link\n   * Serializable}. This is not likely to be a good encoding, so should be used only for tests,\n   * where data volume is small and minor costs are not critical.\n   */\n  private static class SerializableArrayViaCoder<T> implements SerializableSupplier<T[]> {\n    /** Cached value that is not serialized. */\n    @SuppressFBWarnings(\"SE_TRANSIENT_FIELD_NOT_RESTORED\")\n    private transient T @Nullable [] value;\n\n    /** The bytes of {@link #value} when encoded via {@link #coder}. */\n    private byte[] encodedValue;","sourceCodeStart":779,"sourceCodeEnd":815,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/testing/SerializableMatchers.java#L779-L815","documentation":"In SerializableViaCoder.get(), the cached encoded byte array is lazily decoded back into the value using the coder. A CoderException during decodeFromByteArray is wrapped in a RuntimeException with this message, typically after the value was re-materialized on a deserialization side (e.g. a worker).","triggerScenarios":"Calling get() on a SerializableViaCoder whose encoded bytes were produced with a different coder version/type than the one deserializing, or whose bytes are corrupt/truncated after Java serialization round-trip.","commonSituations":"Coder class changed between build and runtime environments (dependency version skew driver vs worker); coders that are not deterministic across versions; classpath differences on cluster workers.","solutions":["Ensure the coder dependency versions match between the job submission environment and workers.","Catch and inspect the CoderException cause to identify the exact decode failure.","Verify the encoded bytes are intact — re-encode and compare in a unit test."],"exampleFix":"// before\nCoder<T> coder = loadCoderDynamically();\n// after\nCoder<T> coder = theStableCoderMatchingEncodingVersion; // pin coder version in pom","handlingStrategy":"try-catch","validationCode":"// round-trip check before relying on the matcher\ncoder.verifyDeterministic(); CoderUtils.decodeFromByteArray(coder, CoderUtils.encodeToByteArray(coder, sample));","typeGuard":null,"tryCatchPattern":"try { T v = viaCoder.get(); } catch (RuntimeException e) { logger.error(\"decode failed; check coder version skew\", e.getCause()); }","preventionTips":["Keep Beam dependency versions identical on driver and workers.","Use deterministic, version-stable coders in test matchers.","Add round-trip encode/decode tests for coders used with SerializableMatchers."],"tags":["java","deserialization","coder","apache-beam"],"backgroundTag":"json-unmarshal-failed","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"}