You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Bernd Eckenfels <ec...@zusammenkunft.net> on 2014/02/15 22:36:11 UTC

Re: svn commit: r1568683 - in /commons/proper/fileupload/trunk/src: changes/changes.xml main/java/org/apache/commons/fileupload/disk/DiskFileItem.java

Am Sat, 15 Feb 2014 21:30:48 -0000
schrieb sebb@apache.org:

> Author: sebb
> Date: Sat Feb 15 21:30:47 2014
> New Revision: 1568683
> 
> URL: http://svn.apache.org/r1568683
> Log:
> FILEUPLOAD-246 FileUpload should use IOUtils.closeQuietly where
> relevant
> 
> Modified:
>     commons/proper/fileupload/trunk/src/changes/changes.xml
>     commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
> 
> Modified: commons/proper/fileupload/trunk/src/changes/changes.xml
> URL:
> http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/changes/changes.xml?rev=1568683&r1=1568682&r2=1568683&view=diff
> ==============================================================================
> --- commons/proper/fileupload/trunk/src/changes/changes.xml
> (original) +++
> commons/proper/fileupload/trunk/src/changes/changes.xml Sat Feb 15
> 21:30:47 2014 @@ -45,6 +45,7 @@ The <action> type attribute can be
> add,u <body> <release version="1.4" date="TBA" description= "TBA">
> +      <action issue="FILEUPLOAD-246" dev="sebb"
> type="update">FileUpload should use IOUtils.closeQuietly where
> relevant</action> <action issue="FILEUPLOAD-245" dev="sebb"
> type="fix">DiskFileItem.get() may not fully read the data</action>
> <action issue="FILEUPLOAD-243" dev="sebb" type="update" due-to="Ville
> Skyttä">Make some MultipartStream private fields final</action>
> </release>
> 
> Modified:
> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java?rev=1568683&r1=1568682&r2=1568683&view=diff
> ==============================================================================
> ---
> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
> (original) +++
> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
> Sat Feb 15 21:30:47 2014 @@ -316,13 +316,7 @@ public class
> DiskFileItem } catch (IOException e) { fileData = null; } finally {
> -            if (fis != null) {
> -                try {
> -                    fis.close();
> -                } catch (IOException e) {
> -                    // ignore
> -                }
> -            }
> +            IOUtils.closeQuietly(fis);
>          }
>  
>          return fileData;
> @@ -418,20 +412,8 @@ public class DiskFileItem
>                                  new FileOutputStream(file));
>                          IOUtils.copy(in, out);
>                      } finally {
> -                        if (in != null) {
> -                            try {
> -                                in.close();
> -                            } catch (IOException e) {
> -                                // ignore
> -                            }
> -                        }
> -                        if (out != null) {
> -                            try {
> -                                out.close();
> -                            } catch (IOException e) {
> -                                // ignore
> -                            }
> -                        }
> +                        IOUtils.closeQuietly(in);
> +                        IOUtils.closeQuietly(out);

Is it really safe to close output stream quitly in this situations?
There are file systems which return write problems only on the close().
It is most always never a good idea to close an output stream and
ignore errors.

Bernd

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1568683 - in /commons/proper/fileupload/trunk/src: changes/changes.xml main/java/org/apache/commons/fileupload/disk/DiskFileItem.java

Posted by sebb <se...@gmail.com>.
On 15 February 2014 21:36, Bernd Eckenfels <ec...@zusammenkunft.net> wrote:
> Am Sat, 15 Feb 2014 21:30:48 -0000
> schrieb sebb@apache.org:
>
>> Author: sebb
>> Date: Sat Feb 15 21:30:47 2014
>> New Revision: 1568683
>>
>> URL: http://svn.apache.org/r1568683
>> Log:
>> FILEUPLOAD-246 FileUpload should use IOUtils.closeQuietly where
>> relevant
>>
>> Modified:
>>     commons/proper/fileupload/trunk/src/changes/changes.xml
>>     commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
>>
>> Modified: commons/proper/fileupload/trunk/src/changes/changes.xml
>> URL:
>> http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/changes/changes.xml?rev=1568683&r1=1568682&r2=1568683&view=diff
>> ==============================================================================
>> --- commons/proper/fileupload/trunk/src/changes/changes.xml
>> (original) +++
>> commons/proper/fileupload/trunk/src/changes/changes.xml Sat Feb 15
>> 21:30:47 2014 @@ -45,6 +45,7 @@ The <action> type attribute can be
>> add,u <body> <release version="1.4" date="TBA" description= "TBA">
>> +      <action issue="FILEUPLOAD-246" dev="sebb"
>> type="update">FileUpload should use IOUtils.closeQuietly where
>> relevant</action> <action issue="FILEUPLOAD-245" dev="sebb"
>> type="fix">DiskFileItem.get() may not fully read the data</action>
>> <action issue="FILEUPLOAD-243" dev="sebb" type="update" due-to="Ville
>> Skyttä">Make some MultipartStream private fields final</action>
>> </release>
>>
>> Modified:
>> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
>> URL:
>> http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java?rev=1568683&r1=1568682&r2=1568683&view=diff
>> ==============================================================================
>> ---
>> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
>> (original) +++
>> commons/proper/fileupload/trunk/src/main/java/org/apache/commons/fileupload/disk/DiskFileItem.java
>> Sat Feb 15 21:30:47 2014 @@ -316,13 +316,7 @@ public class
>> DiskFileItem } catch (IOException e) { fileData = null; } finally {
>> -            if (fis != null) {
>> -                try {
>> -                    fis.close();
>> -                } catch (IOException e) {
>> -                    // ignore
>> -                }
>> -            }
>> +            IOUtils.closeQuietly(fis);
>>          }
>>
>>          return fileData;
>> @@ -418,20 +412,8 @@ public class DiskFileItem
>>                                  new FileOutputStream(file));
>>                          IOUtils.copy(in, out);
>>                      } finally {
>> -                        if (in != null) {
>> -                            try {
>> -                                in.close();
>> -                            } catch (IOException e) {
>> -                                // ignore
>> -                            }
>> -                        }
>> -                        if (out != null) {
>> -                            try {
>> -                                out.close();
>> -                            } catch (IOException e) {
>> -                                // ignore
>> -                            }
>> -                        }
>> +                        IOUtils.closeQuietly(in);
>> +                        IOUtils.closeQuietly(out);
>
> Is it really safe to close output stream quitly in this situations?
> There are file systems which return write problems only on the close().
> It is most always never a good idea to close an output stream and
> ignore errors.

That is a separate issue.
I merely replaced the code with a shorthand; the behaviour is unchanged.

> Bernd
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org