[
https://issues.apache.org/jira/browse/FILEUPLOAD-134?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12760262#action_12760262
]
Mike Arvela commented on FILEUPLOAD-134:
----------------------------------------
Jochen, it turns out the resolution you described only affects the sympton and
not the original problem. The dfos is not initialized at all unless
getOutputStream() is manually invoked. As I see it, the fix would be to
initialize the dfos as soon as the object is created.
I came across this problem when trying to wrap a newly created DiskFileItem in
a MultipartFile, which causes getSize() to be called, which ultimately leads to
a call of dfos.isInMemory() (line 306 in DiskFileItem.java), which results to
an NPE.
> A factory-created DiskFileItem does not have an initialized dfos, causing
> NullPointerExceptions if getOutputStream() is not called.
> -----------------------------------------------------------------------------------------------------------------------------------
>
> Key: FILEUPLOAD-134
> URL: https://issues.apache.org/jira/browse/FILEUPLOAD-134
> Project: Commons FileUpload
> Issue Type: Bug
> Affects Versions: 1.2
> Reporter: Thomas Vandahl
> Fix For: 1.2.1
>
>
> When upgrading the Turbine code to commons-fileupload 1.2, I got NPEs in Unit
> tests dealing with DiskFileItems. In that special case, a FileItem was
> created like this:
> ParameterParser pp = new DefaultParameterParser();
> DiskFileItemFactory factory = new DiskFileItemFactory(10240, new
> File("."));
> FileItem test = factory.createItem("upload-field",
> "application/octet-stream", false, null);
> pp.add("upload-field", test);
> assertTrue(pp.toString().startsWith("{upload-field=[name=null"));
> pp.toString() causes a call to test.toString() which (among other things)
> calls dfos.getFile(). This fails because dfos is not initialized before
> getOutputStream() is called.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.