RFR: 4799358: BufferOutputStream.write() should immediately throw IOExcept on closed stream [v2]
Brian Burkhalter
bpb at openjdk.org
Wed Aug 23 21:45:23 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
src/java.base/share/classes/java/io/FilterOutputStream.java line 210:
> 208: */
> 209: boolean isOpen(){
> 210: return !closed;
Wouldn't you want `synchronized (closeLock)` here?
test/jdk/java/io/BufferedOutputStream/WriteAfterClose.java line 36:
> 34: import java.io.OutputStream;
> 35: import java.io.File;
> 36: import java.io.FileOutputStream;
The imports should be in alphabetical order per convention.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15361#discussion_r1303571619
PR Review Comment: https://git.openjdk.org/jdk/pull/15361#discussion_r1303572211
More information about the core-libs-dev
mailing list