Repository navigation
Description
Steps to reproduce
- On Android, call
openFile()/openFiles()fromfile_selector. - Select a document whose content provider cannot serve its bytes when the result comes back:
ContentResolver#openInputStream(uri)returns null (for example after the provider process crashed). The provider still answers the metadata query, so a size is known and the read is attempted.
Expected results
The call completes with the plugin's existing "Failed to read file: <uri>" error, and the app keeps running.
Actual results
FileSelectorApiImpl#toFileResponse opens the stream in a try-with-resources (a null resource is legal there) and hands it to DataInputStream#readFully, which dereferences it:
java.lang.NullPointerException
at java.io.DataInputStream.readFully(...)
at dev.flutter.packages.file_selector_android.FileSelectorApiImpl.toFileResponse(FileSelectorApiImpl.java:355)
at dev.flutter.packages.file_selector_android.FileSelectorApiImpl$2.onResult(...)
Only IOException is caught there, and toFileResponse runs inside the onActivityResult listener — the main thread — so the NPE is uncaught and takes the process down. FileUtils.getPathFromCopyOfFileFromUri has the same unguarded copy(inputStream, …) one step later. This is the file_selector_android sibling of the image_picker_android null-stream crash (see #191988); #159568 covered the copy-failure case in the same callback but not a null stream.
Code sample
Any openFile() / openFiles() call; the trigger is the provider's behaviour, not app code.
Logs
Mechanism confirmed from the source on main (packages/file_selector/file_selector_android/android/src/main/java/dev/flutter/packages/file_selector_android/FileSelectorApiImpl.java, toFileResponse; FileUtils.java, getPathFromCopyOfFileFromUri).
Flutter Doctor output
Not environment-specific.
Activity
jesswrd commentedon Sep 1, 2026
Whoever takes this on can revisit this flutter/packages#12683. Looks good but could not be completed due to personal CLA signing issues.
mboetger commentedon Sep 14, 2026
Fixed with flutter/packages#12716
github-actions commentedon Sep 28, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.