[
https://issues.apache.org/jira/browse/FILEUPLOAD-295?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18003768#comment-18003768
]
Stephan Markwalder commented on FILEUPLOAD-295:
-----------------------------------------------
*A quick update after the release of Commons FileUpload 1.6.0*
Due to changes in Commons IO's {{ThresholdingOutputStream}} (probably in
2.16.0) the behavior of Commons FileUpload has changed once more. A value of -1
passed as {{sizeThreshold}} to {{DiskFileItem}} is now automatically changed to
0 in the constructor of {{{}ThresholdingOutputStream{}}}:
{{this.threshold = threshold < 0 ? 0 : threshold;}}
The behavior of Commons FileUpload's API now seems to be self-consistent again
when uploading an empty file:
* isInMemory() --> returns true
* getSize() --> returns 0
* getStoreLocation() --> returns null
However, it is impossible to configure Commons FileUpload so that it ALWAYS
creates a file on disk, even for empty files.
> 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)