commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jochen Wiedmann (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (FILEUPLOAD-184) Generic exception thrown in FileItem#write method
Date Wed, 08 Jul 2015 09:25:04 GMT

     [ https://issues.apache.org/jira/browse/FILEUPLOAD-184?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Jochen Wiedmann resolved FILEUPLOAD-184.
----------------------------------------
    Resolution: Won't Fix
      Assignee: Jochen Wiedmann

I generally agree with your view. That said, replacing Exception with a subclass in  method
signature, would be an incompatible change. And we are keen to avoid that. So, I am closing
as WONTFIX. Sorry!


> Generic exception thrown in FileItem#write method
> -------------------------------------------------
>
>                 Key: FILEUPLOAD-184
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-184
>             Project: Commons FileUpload
>          Issue Type: Improvement
>    Affects Versions: 1.2.2
>         Environment: Windows 7, jdk 6
>            Reporter: Zixiang Tang
>            Assignee: Jochen Wiedmann
>            Priority: Minor
>
> I write a servlet to handle file upload request. It works fine, all files can be received
correctly.
> However, I find that the write method in FileItem interface throws generic exception.
I don't think it's a good practice. Throwing generic exception directly means we could not
know what exception happened exactly. Also, we have to catch generic exception in our class,
it is not a proper way. Ref to http://www.javaworld.com/javaworld/jw-10-2003/jw-1003-generics.html
> And I have look the source code of DiskFileItem, which seems to be the only implementation
of FileItem interface. In write method, FileUploadException will be thrown only when isInMemory()
return false and getStoreLocation() is null, other exceptions are thrown directly without
any handle, though the comment above FileUploadException thrown sentence is "For whatever
reason we cannot write file to disk."
> I think a proper way of error handling in write method is to throw IllegalArgumentException
and FileUploadException. IllegalArgumentException will be thrown if file argument is null,
and other exceptions caused inside write method will be wrapped as FileUploadException and
re-throw.
> Anyway, FileUploadException will be thrown "For whatever reason we cannot write file
to disk.", right?
> Please point out any mistake if I'm wrong, I really appreciate your works. :)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message