commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Elijah Zupancic <>
Subject Re: [io] ClosedOutputStream#flush
Date Wed, 16 Aug 2017 01:12:51 GMT
I inspected the code path and I think this bug has merit. Consider the
following sample application:


import java.nio.charset.StandardCharsets;

public class BrokenShield {
    public static void main(String[] argv) throws IOException {
        File file = File.createTempFile("broken-shield", "txt");

        byte[] arbitraryData = "Hello World ".getBytes(StandardCharsets.UTF_8);

        FileOutputStream fout = new FileOutputStream(file);
        BufferedOutputStream bout = new BufferedOutputStream(fout, 99999);
        CloseShieldOutputStream cout = new CloseShieldOutputStream(fout);

        try {
            // This should work because we haven't tried to close the stream

            // Here we pretend this is some stupid library that insists on
            // closing a stream when it shouldn't.

            // After we try to close the stream, new data can't be written to
            // the stream. For example: cout.write(arbitraryData);
            // Would throw an exception like:
            // write(72) failed: stream is closed

            // However, if we call flush(), no exception is thrown - this is
            // inconsistent with the behavior of write()
        } finally {
            // We properly close the stream we have to use the underlying
            // stream like you would expect.

        try (FileInputStream fin = new FileInputStream(file)) {
            String data = IOUtils.toString(fin, StandardCharsets.UTF_8);

On Thu, Aug 10, 2017 at 4:54 PM, Tomas Celaya <> wrote:
> Would anyone mind taking a look at this issue regarding the flush method on
> ClosedOutputStream?
> The change is relatively trivial and the attached patch includes a test
> case. I understand the impact is significant but I think it would make
> ClosedOutputStream behave more consistently with what a user would expect.
> – Tomas Celaya

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message