{"record":{"id":"1876403bb469e04e","repo":"apache/beam","slug":"unexpected-ioexception-closing-bytearrayinputstream","errorCode":null,"errorMessage":"Unexpected IOException closing ByteArrayInputStream","messagePattern":"Unexpected IOException closing ByteArrayInputStream","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/util/ExposedByteArrayInputStream.java","lineNumber":50,"sourceCode":"  }\n\n  /** Read all remaining bytes. */\n  public byte[] readAll() throws IOException {\n    if (pos == 0 && count == buf.length) {\n      pos = count;\n      return buf;\n    }\n    byte[] ret = new byte[count - pos];\n    super.read(ret);\n    return ret;\n  }\n\n  @Override\n  public void close() {\n    try {\n      super.close();\n    } catch (IOException exn) {\n      throw new RuntimeException(\"Unexpected IOException closing ByteArrayInputStream\", exn);\n    }\n  }\n}\n","sourceCodeStart":32,"sourceCodeEnd":54,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ExposedByteArrayInputStream.java#L32-L54","documentation":"ExposedByteArrayInputStream.close() delegates to ByteArrayInputStream.close(), which is documented to never throw IOException. This RuntimeException is a defensive guard: if an IOException somehow surfaces while closing the in-memory stream, it indicates a JVM/library-level bug, so it is rethrown unchecked with this message.","triggerScenarios":"Calling close() on an ExposedByteArrayInputStream in a code path where ByteArrayInputStream.close() unexpectedly throws IOException — theoretically impossible per the JDK contract, so effectively only via exotic stream subclassing or JVM anomalies.","commonSituations":"Extremely rare; encountered only when stream implementations are swapped, instrumented, or when running under a JVM with a broken/patched java.io implementation. Practically a 'this should never happen' assertion.","solutions":["Treat it as an internal invariant violation: report it to the Beam project with the full stack trace","Check whether a custom or instrumented stream/JVM version is replacing the JDK ByteArrayInputStream behavior","If it appears in cleanup code, inspect the cause — the message is always secondary to the underlying IOException"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  stream.close();\n} catch (RuntimeException e) {\n  if (e.getCause() instanceof IOException) {\n    LOG.error(\"Impossible IOException closing byte stream; JVM/stream anomaly\", e);\n  }\n  throw e;\n}","preventionTips":["Use standard JDK streams; avoid exotic stream subclassing or JVM instrumentation","Treat any occurrence as a bug report candidate with full stack trace"],"tags":["java","io","stream","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}