{"record":{"id":"789e5ad33f317fbe","repo":"apache/beam","slug":"eof-encountered-decoding-1-byte-from-input-stream","errorCode":null,"errorMessage":"EOF encountered decoding 1 byte from input stream","messagePattern":"EOF encountered decoding 1 byte from input stream","errorType":"exception","errorClass":"EOFException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/coders/ByteCoder.java","lineNumber":55,"sourceCode":"  private static final TypeDescriptor<Byte> TYPE_DESCRIPTOR = new TypeDescriptor<Byte>() {};\n\n  private ByteCoder() {}\n\n  @Override\n  public void encode(Byte value, OutputStream outStream) throws IOException, CoderException {\n    if (value == null) {\n      throw new CoderException(\"cannot encode a null Byte\");\n    }\n    outStream.write(value);\n  }\n\n  @Override\n  public Byte decode(InputStream inStream) throws IOException, CoderException {\n    try {\n      // value will be between 0-255, -1 for EOF\n      int value = inStream.read();\n      if (value == -1) {\n        throw new EOFException(\"EOF encountered decoding 1 byte from input stream\");\n      }\n      return (byte) value;\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  /**\n   * {@inheritDoc}\n   *\n   * <p>{@link ByteCoder} will never throw a {@link Coder.NonDeterministicException}; bytes can\n   * always be encoded deterministically.\n   */\n  @Override\n  public void verifyDeterministic() {}\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/coders/ByteCoder.java#L37-L73","documentation":"ByteCoder.decode throws EOFException when inStream.read() returns -1, i.e. the stream ended before the 1 byte needed to decode a Byte was available. This indicates truncated, empty, or misaligned encoded input.","triggerScenarios":"Decoding from an exhausted stream (empty file, truncated record, wrong offset), or a framing loop that attempts one more decode after the last encoded element.","commonSituations":"Reading past the last element in length-prefixed data, byte-count errors in custom framing, network streams cut short, closed/finished streams.","solutions":["Check stream availability / remaining length before calling decode","Fix the framing loop so it stops at exactly the number of encoded elements written","Catch EOFException/CoderException and treat it as end-of-data if legitimate","Regenerate or re-fetch the truncated input data"],"exampleFix":"// before\nwhile (true) { out.add(coder.decode(in)); }\n// after\nwhile (in.available() > 0) {\n  try {\n    out.add(coder.decode(in));\n  } catch (CoderException | EOFException e) {\n    break; // clean end of data\n  }\n}","handlingStrategy":"try-catch","validationCode":"if (inStream.available() < 1) { throw new IllegalStateException(\"stream exhausted before Byte decode\"); }","typeGuard":null,"tryCatchPattern":"try { Byte b = ByteCoder.of().decode(in); } catch (CoderException | EOFException e) { /* truncated input: stop loop or dead-letter */ }","preventionTips":["Track the number of encoded elements explicitly instead of decoding until EOF","Use length-prefixed framing so element boundaries are known"],"tags":["java","beam","decoding","eof"],"backgroundTag":"unexpected-eof-while-reading","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"}