{"record":{"id":"4a2deeb6db48a4e1","repo":"apache/beam","slug":"coderexception","errorCode":null,"errorMessage":"CoderException","messagePattern":"CoderException","errorType":"exception","errorClass":"CoderException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/VarLongCoder.java","lineNumber":62,"sourceCode":"\n  private VarLongCoder() {}\n\n  @Override\n  public void encode(Long value, OutputStream outStream) throws IOException, CoderException {\n    if (value == null) {\n      throw new CoderException(\"cannot encode a null Long\");\n    }\n    VarInt.encode(value, outStream);\n  }\n\n  @Override\n  public Long decode(InputStream inStream) throws IOException, CoderException {\n    try {\n      return VarInt.decodeLong(inStream);\n    } catch (EOFException | UTFDataFormatException exn) {\n      // These exceptions correspond to decoding problems, so change\n      // what kind of exception they're branded as.\n      throw new CoderException(exn);\n    }\n  }\n\n  @Override\n  public List<? extends Coder<?>> getCoderArguments() {\n    return Collections.emptyList();\n  }\n\n  @Override\n  public void verifyDeterministic() {}\n\n  /**\n   * {@inheritDoc}\n   *\n   * @return {@code true}. {@link VarLongCoder} is injective.\n   */\n  @Override\n  public boolean consistentWithEquals() {","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/VarLongCoder.java#L44-L80","documentation":"VarLongCoder.decode reads a varint-encoded long and rebrands EOFException and UTFDataFormatException — the signals of truncated or corrupt input — as CoderException. This means the byte stream ended mid-value or contained bytes that do not form a valid varint long.","triggerScenarios":"Decoding from a truncated buffer/stream (fewer bytes than the varint needs), decoding a stream written with an incompatible coder/format, or reading past the end of a message.","commonSituations":"Network/gRPC framing bugs that split or truncate messages, mixing coder versions between writer and reader, offset bugs when decoding elements out of a shared byte buffer.","solutions":["Verify the byte stream is complete and correctly framed; check that all written bytes are flushed before decoding.","Ensure the same coder (and version) used for encoding is used for decoding.","Wrap decode() in try/catch for CoderException and log/handle corrupt data instead of crashing the pipeline."],"exampleFix":"// before\nLong v = VarLongCoder.of().decode(inStream); // throws on truncated input\n// after\ntry {\n  Long v = VarLongCoder.of().decode(inStream);\n} catch (CoderException e) {\n  // handle truncated/corrupt element: log offset, skip, or fail with context\n  throw new IOException(\"Corrupt encoded Long at stream position \" + pos, e);\n}","handlingStrategy":"try-catch","validationCode":"if (inStream.available() < 1) { throw new EOFException(\"empty buffer before VarLong decode\"); }","typeGuard":null,"tryCatchPattern":"try { v = VarLongCoder.of().decode(in); } catch (CoderException e) { /* truncated/corrupt: log, resync stream, or fail bundle */ }","preventionTips":["Keep writer and reader Beam versions and coders in sync","Ensure gRPC framing flushes complete messages before decode","Add stream-position context to decode error handling"],"tags":["beam","coder","decoding","truncated-data"],"backgroundTag":"schema-validation-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"}