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

Gary D. Gregory edited comment on FILEUPLOAD-295 at 7/8/25 12:47 PM:
---------------------------------------------------------------------

Hello [[email protected]]

Thank you for your report.

Would your use case be accommodated with a new feature/bug fix in FileUpload? 
If so, would you be willing to submit a pull-request on GitHub?

G.


was (Author: garydgregory):
Hello [[email protected]]

Thank you for your report.

Would your use case be accommodated with a new feature in FileUpload? If so, 
would you be willing to submit a pull-request on GitHub?

G.

> 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
(v8.20.10#820010)

Reply via email to