You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Fabian Barney (Issue Comment Edited) (JIRA)" <ji...@apache.org> on 2012/02/17 18:52:00 UTC

[jira] [Issue Comment Edited] (IO-303) TeeOutputStream fails executing branch.close() when main.close() raised an exception

    [ https://issues.apache.org/jira/browse/IO-303?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13210346#comment-13210346 ] 

Fabian Barney edited comment on IO-303 at 2/17/12 5:51 PM:
-----------------------------------------------------------

In my code I prefer throwing the first one. There is one exception when a latter Throwable occurrs and it is an Error and the former not.
In my opinion this is the Throwable you want to see.

Another approach is to throw something like a MultiIOException containing all occurred exceptions.

I agree that this all is not a real pleasure, but better than leaving resources open that can be closed successfully.
I've written a MultiOutputStream yesterday: https://github.com/fabian-barney/Utils/blob/master/utils/src/com/barney4j/utils/io/MultiOutputStream.java

I am not sure for myself that I made the right decision here.
                
      was (Author: fabian.barney):
    In my code I prefer throwing the first one. There is one exception when a latter Throwable occurrs and it is an Error and the former not.
In my opinion this is the Throwable you want to see.

Another approach is to throw something like a MultiIOException containing all occurred exceptions.

I agree that this all is not a real pleasure, but better than leaving resources open that might be closed successfully.
I've written a MultiOutputStream yesterday: https://github.com/fabian-barney/Utils/blob/master/utils/src/com/barney4j/utils/io/MultiOutputStream.java

I am not sure for myself that I made the right decision here.
                  
> TeeOutputStream fails executing branch.close() when main.close() raised an exception
> ------------------------------------------------------------------------------------
>
>                 Key: IO-303
>                 URL: https://issues.apache.org/jira/browse/IO-303
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 2.1
>            Reporter: Fabian Barney
>              Labels: close, stream
>
> TeeOutputStream.close() looks like this:
> {code:title=TeeOutputStream.java|borderStyle=solid}
>     /**
>      * Closes both streams. 
>      * @throws IOException if an I/O error occurs
>      */
>     @Override
>     public void close() throws IOException {
>         super.close();
>         this.branch.close();
>     }
> {code} 
> It is obvious that {{this.branch.close()}} is not executed when {{super.close()}} raises an exception. {{super.close()}} may in fact raise an IOException since {{ProxyOutputStream.handleIOException(IOException)}} is not overridden.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira