[
https://issues.apache.org/jira/browse/FILEUPLOAD-295?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18070316#comment-18070316
]
Johan Compagner edited comment on FILEUPLOAD-295 at 4/1/26 12:13 PM:
---------------------------------------------------------------------
this commit
[https://github.com/apache/commons-fileupload/commit/d469648cf1070777d762ffff23844a62170a55cd#r181185918]
does break stuff now because getString(charset) can bomb out now with a null
pointer..
getString() without charset was adjusted for the behavior that get() now
returns null instead at least a byte[0] (why was this changed, why not just
always return at least an empty byte array)
i guess now also getString() (both variants) can return a null which it didn't
do before
was (Author: [email protected]):
this commit
[https://github.com/apache/commons-fileupload/commit/d469648cf1070777d762ffff23844a62170a55cd#r181185918]
does break stuff now because getString(charset) can bomb out now with a null
pointer..
getString() without charset was adjusted for the behavior that get() now
returns null instead at least a byte[0] (why was this changed, why not just
always return at least an empty byte array)
i guess now also getString() (both variants can return a null which it didn't
do before)
> 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
> Assignee: Jochen Wiedmann
> 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)