Description
FileUtils.java
will return a null path in a couple of exception cases:
https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector_android/android/src/main/java/dev/flutter/packages/file_selector_android/FileUtils.java#L139
The idea behind this approach was as an alternative to throwing errors in Java code, which would crash the app (originally in image_picker
, these two plugins share much of this code)
flutter/packages#4004
But this approach doesn't actually prevent a crash, because the path is marked as not nullable. The path gets returned
https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector_android/android/src/main/java/dev/flutter/packages/file_selector_android/FileSelectorApiImpl.java#L360
and then the builder will try to set that path on the object, at which point the generated Java object does the following check
https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector_android/android/src/main/java/dev/flutter/packages/file_selector_android/GeneratedFileSelectorApi.java#L77
and throws an IllegalStateException
if the path is null.
We should probably switch to surfacing exceptions in dart, following the pattern introduced in flutter/packages#8184.
image_picker
is likely also affected, though I haven't checked.