Repository navigation
Description
Steps to reproduce
- On Android, call
ImagePicker().pickMultiImage()(orpickImage(source: ImageSource.gallery)), with or withoutuseAndroidPhotoPicker. - Select an item whose content provider cannot serve its bytes when the result comes back:
ContentResolver#openInputStream(uri)returns null for it. In the field this happens on some OEM providers (seen on a Xiaomi device running Android 10) for items the provider recently failed on, e.g. a cloud-only photo it could not fetch, or after the provider process crashed.
Expected results
The pick fails with the plugin's existing missing_valid_image_uri error (the same way a null URI does), and the app keeps running.
Actual results
The process dies. FileUtils.getPathFromUri opens the stream in a try-with-resources (a null resource is legal there), then hands it straight to copy():
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.InputStream.read(byte[])' on a null object reference
at io.flutter.plugins.imagepicker.FileUtils.copy (FileUtils.java:186)
at io.flutter.plugins.imagepicker.FileUtils.getPathFromUri (FileUtils.java:83)
at io.flutter.plugins.imagepicker.ImagePickerDelegate.getPathsFromIntent (ImagePickerDelegate.java:741)
at io.flutter.plugins.imagepicker.ImagePickerDelegate.handleChooseMultiImageResult (ImagePickerDelegate.java:831)
at io.flutter.plugins.imagepicker.ImagePickerDelegate.lambda$onActivityResult$1 (ImagePickerDelegate.java:692)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
getPathFromUri catches IOException, SecurityException and IllegalArgumentException only, and the handler runs on the delegate's own executor thread, so the NPE is uncaught and takes the process down. The sibling case (a null URI) was fixed in flutter/packages#5009; the null stream right after it is still unguarded on main. A one-line null check returning null from getPathFromUri routes it onto the existing missing_valid_image_uri path.
Code sample
Any pickMultiImage() call; the trigger is the provider's behaviour, not app code.
Logs
See the stack trace above (from a Play Console crash report; image_picker_android 0.8.13+19, Android 10 / API 29).
Flutter Doctor output
Not environment-specific: the code path is identical on main (packages/image_picker/image_picker_android/android/src/main/java/io/flutter/plugins/imagepicker/FileUtils.java, getPathFromUri).
Activity
mbcorona commentedon Aug 29, 2026
Hi @ralatorre , thanks for the report and precise analysis, routing to the Android team for evaluation.
jesswrd commentedon Sep 1, 2026
Whoever takes this on can revisit this flutter/packages#12682. Looks good but could not be completed due to personal CLA signing issues.
[image_picker] Handle a null stream from openInputStream (flutter#12718)
github-actions commentedon Sep 24, 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.