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

Jochen Wiedmann commented on FILEUPLOAD-295:
--------------------------------------------

I admit, that I wouldn't design it like this, if this were a new API. On the 
other hand, FileUpload is quite established, and I do not consider this a 
serious problem. So, I am suggesting to resolve this as WONTFIX.

 

> DiskFileItem: getStoreLocation() may return non-existing file
> -------------------------------------------------------------
>
>                 Key: FILEUPLOAD-295
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-295
>             Project: Commons FileUpload
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Stephan Markwalder
>            Priority: Minor
>
> *How to reproduce*
>  # Create a DiskFileItem with threshold set to -1 (force save to disk).
>  # Get OutputStream from DiskFileItem.
>  # Close OutputStream without calling any write(...) method (e.g., because 
> the uploaded file is empty).
>  # Test the return value of the following methods:
>  ** isInMemory() --> returns false (OK)
>  ** getSize() --> returns 0 (OK)
>  ** getStoreLocation() --> returns a File object (OK), but the file does not 
> exist (FAILURE).
> I think this is an inconsistency. If isInMemory() returns false adn 
> getStoreLocation() returns a File object, the file should also exist.
> Java code (run with -ea to enable assertions):
> {code:java}
> // create a DiskFileItem
> int sizeThreshold = -1; // always store to disk
> File repository = null; // use temporary folder
> DiskFileItem item = new DiskFileItem("file", "text/plain", false, "file.txt", 
> sizeThreshold, repository);
> OutputStream outputStream = item.getOutputStream();
> // do not write to stream <-- IMPORTANT
> outputStream.close();
> // assert that data has been stored to disk
> assert !item.isInMemory(); // pass
> assert item.getSize() == 0; // pass
> assert item.getStoreLocation() != null; // pass
> assert item.getStoreLocation().isFile(); // fails
> {code}
> When adding a call to outputStream.write(new byte[0]), the behavior changes 
> and the empty file is created on disk.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to