Skip to content

[image_picker] Android: uncaught NullPointerException in FileUtils.copy when openInputStream returns null (process crash) #191988

Closed
flutter/packages
#12718

Description

@ralatorre

Steps to reproduce

  1. On Android, call ImagePicker().pickMultiImage() (or pickImage(source: ImageSource.gallery)), with or without useAndroidPhotoPicker.
  2. 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

  1. added
    platform-androidAndroid applications specifically
    packageflutter/packages repository. See also p: labels.
    in triagePresently being triaged by the triage team
    c: crashStack traces logged to the console
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-androidOwned by Android platform team
    fyi-ecosystemFor the attention of Ecosystem team
    and removed
    in triagePresently being triaged by the triage team
    on Aug 29, 2026
  2. mbcorona commented on Aug 29, 2026

    @mbcorona
    Member

    Hi @ralatorre , thanks for the report and precise analysis, routing to the Android team for evaluation.

  3. added
    P2Important issues not at the top of the work list
    triaged-androidTriaged by Android platform team
    on Sep 1, 2026
  4. jesswrd commented on Sep 1, 2026

    @jesswrd
    Contributor

    Whoever takes this on can revisit this flutter/packages#12682. Looks good but could not be completed due to personal CLA signing issues.

  5. github-actions commented on Sep 24, 2026

    @github-actions

    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 -v and a minimal reproduction of the issue.

  6. locked as resolved and limited conversation to collaborators on Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: crashStack traces logged to the consolehas reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: image_pickerThe Image Picker plugin.packageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions