apache/beam · error · RuntimeException
Unexpected IOException closing ByteArrayInputStream
Error message
Unexpected IOException closing ByteArrayInputStream
What it means
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.
Source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/util/ExposedByteArrayInputStream.java:50
}
/** Read all remaining bytes. */
public byte[] readAll() throws IOException {
if (pos == 0 && count == buf.length) {
pos = count;
return buf;
}
byte[] ret = new byte[count - pos];
super.read(ret);
return ret;
}
@Override
public void close() {
try {
super.close();
} catch (IOException exn) {
throw new RuntimeException("Unexpected IOException closing ByteArrayInputStream", exn);
}
}
}
View on GitHub (pinned to 12126d8942)
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
Defensive patterns
Strategy: try-catch
Try / catch
try {
stream.close();
} catch (RuntimeException e) {
if (e.getCause() instanceof IOException) {
LOG.error("Impossible IOException closing byte stream; JVM/stream anomaly", e);
}
throw e;
} Prevention
- Use standard JDK streams; avoid exotic stream subclassing or JVM instrumentation
- Treat any occurrence as a bug report candidate with full stack trace
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Stream has been finished. Can not add any more elements.
- Stream has been finished. Can not write any more data.
- Caller does not own the underlying input stream and should
- Caller does not own the underlying output stream and should
- No block has been successfully read from " + getCurrentSourc
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/1876403bb469e04e.
Report an issue: GitHub.