[
https://issues.apache.org/jira/browse/WICKET-5691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14121350#comment-14121350
]
ASF subversion and git services commented on WICKET-5691:
---------------------------------------------------------
Commit d14ee4515208d2c6820957aa5b9a2afaa5c953dd in wicket's branch
refs/heads/wicket-6.x from adelbene
[ https://git-wip-us.apache.org/repos/asf?p=wicket.git;h=d14ee45 ]
WICKET-5691 Wicket FileUploadField.getFileUploads() should never return
null.
> Wicket FileUploadField.getFileUploads() should never return null.
> -----------------------------------------------------------------
>
> Key: WICKET-5691
> URL: https://issues.apache.org/jira/browse/WICKET-5691
> Project: Wicket
> Issue Type: Improvement
> Components: wicket
> Reporter: Garret Wilson
> Assignee: Andrea Del Bene
> Priority: Minor
>
> {{FileUploadField}} at one point in its history (as far as I can tell) only
> supported uploading a single file (as did HTML). Thus
> {{FileUploadField.getFileUpload()}} returned a {{FileUpload}} or {{null}} if
> there was no file uploaded. This is correct and works as expected.
> After browsers added support for multiple file uploads, Wicket appropriately
> added the {{FileUploadField.getFileUploads()}} method, which returns a
> {{List<FileUpload>}}. This method's API documentation doesn't indicate
> whether it returns {{null}}, a deficiency which itself should be corrected.
> In fact the documentation seems to imply that {{null}} will never be
> returned. The expectation from common practice is that a method returning a
> collection will never return {{null}}, unless {{null}} indicates something
> semantically distinct from an empty collection.
> Unfortunately this method returns {{null}} when there are no files selected
> for upload. This goes against developer expectation, and moreover serves no
> semantic value, as an empty list would be just as appropriate (more
> appropriate, actually) to indicate that no files were selected. It makes the
> developer add extra, unnecessary code:
> {code}
> if(fileUpload.getFileUploads()==null ||
> fileUpload.getFileUploads().isEmpty()) {
> return; //no files to process
> }
> {code}
> I recommend changing {{FileUploadField.getFileUploads()}} so that it never
> returns {{null}} (but may return an empty list), and indicate such in the API
> documentation. The currently implementation runs the risk of an unexpected
> {{NullPointerException}} for the developer who followed common practice
> expectations and was given no warning from the documentation.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)