Upload#getAcceptedFileTypes should return unmodifiable list
padmalcom opened this issue · 3 comments
Description of the bug
When I open a view that contains an upload component, I get an java.lang.UnsupportedOperationException: null - but only if I add one or more elements to the accepted file types. The view renders fine, when I don't add accepted file types to the upload component.
Expected behavior
I expect the upload component to allow me to add an arbitrary number of strings as accepted file types.
Minimal reproducible example
val buffer = MultiFileMemoryBuffer()
val upload = Upload(buffer)
upload.acceptedFileTypes.add("png")
Versions
- Vaadin / Flow version: 24.4.4
- Java version: 17
- OS version: Windows 11
That Kotlin syntax is equivalent to upload.getAcceptedFileTypes().add("png")
. getAcceptedFileTypes()
is supposed to return a snapshot that is not modifiable since the components needs to send the data to the browser and it would be complicated to detect such changes if directly manipulating the list. It seems like we have omitted to actually wrap the returned collection in Collections.unmodifiableList
which means that it does in some cases just silently ignore the value that you added to the list. We should fix that.
The supported way of defining accepted file types is through upload.setAcceptedFileTypes("png")
. That API is not optimized for cases where you want to add one additional file type to a previously defined list but that's seen as an acceptable tradeoff.
Thank you @Legioth, upload.setAcceptedFileTypes("png")
works fine so I go with this solution.
Renamed the issue as we need to change to return an unmodifiable list and update JavaDoc accordingly.