RFR: 4799358: BufferOutputStream.write() should immediately throw IOExcept on closed stream [v2]

Brian Burkhalter bpb at openjdk.org
Wed Aug 23 21:51:09 UTC 2023


On Wed, 23 Aug 2023 15:01:06 GMT, Vyom Tewari <vtewari at openjdk.org> wrote:

>> 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.
>
> Vyom Tewari has updated the pull request incrementally with one additional commit since the last revision:
> 
>   make the isOpen method to package private

test/jdk/java/io/BufferedOutputStream/WriteAfterClose.java line 61:

> 59:     public static void main(String argv[]) throws IOException {
> 60:         var file = new File(System.getProperty("test.dir", "."), "test.txt");
> 61:         file.createNewFile();

Why not instead do something like?:

var dir = new File(System.getProperty("test.dir", "."));
File file = File.createTempFile("x", "y", dir);

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15361#discussion_r1303575171


More information about the core-libs-dev mailing list