You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Thomas Neidhart (JIRA)" <ji...@apache.org> on 2014/11/11 21:45:34 UTC

[jira] [Resolved] (FILEUPLOAD-252) DiskFileItem#write can lose original IO error

     [ https://issues.apache.org/jira/browse/FILEUPLOAD-252?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Neidhart resolved FILEUPLOAD-252.
----------------------------------------
       Resolution: Fixed
    Fix Version/s: 1.4

Fixed in r1638380.

> DiskFileItem#write can lose original IO error
> ---------------------------------------------
>
>                 Key: FILEUPLOAD-252
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-252
>             Project: Commons FileUpload
>          Issue Type: Bug
>            Reporter: Sebb
>             Fix For: 1.4
>
>
> The method DiskFileItem#write has the following code:
> {code}
> FileOutputStream fout = null;
> try {
>     fout = new FileOutputStream(file);
>     fout.write(get());
> } finally {
>     if (fout != null) {
>         fout.close();
>     }
> }
> {code}
> If the write fails and then the close fails, the write failure will be masked by the close error. It might be better to write the code as:
> {code}
> FileOutputStream fout = null;
> try {
>     fout = new FileOutputStream(file);
>     fout.write(get());
>     fout.close();
> } finally {
>     IOUtils.closeQuietly(fout);
> }
> {code}
> This would ensure that the first error was reported.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)