With the current implementation of BufferedOutputStream if you close the stream and try to write to the closed stream BufferedOutputStream does not throw an IOException until the internal buffer is full. To fix this issue i added a private "ensureOpen" function to BufferedOutputStream which will check if the underline stream is open. If the underline stream is closed "ensureOpen" will throw the IOException.
------------- Commit messages: - 4799358: BufferOutputStream.write() should immediately throw IOException on closed stream Changes: https://git.openjdk.org/jdk/pull/15361/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=15361&range=00 Issue: https://bugs.openjdk.org/browse/JDK-4799358 Stats: 75 lines in 3 files changed: 75 ins; 0 del; 0 mod Patch: https://git.openjdk.org/jdk/pull/15361.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/15361/head:pull/15361 PR: https://git.openjdk.org/jdk/pull/15361