Skip to content

[file_selector] Android: uncaught NullPointerException on the main thread when openInputStream returns null in toFileResponse #191989

Closed

Description

@ralatorre

Steps to reproduce

  1. On Android, call openFile() / openFiles() from file_selector.
  2. 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

  1. added
    c: crashStack traces logged to the console
    platform-androidAndroid applications specifically
    packageflutter/packages repository. See also p: labels.
    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
    on Aug 29, 2026
  2. jesswrd commented on Sep 1, 2026

    @jesswrd
    Contributor

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

  3. added
    triaged-androidTriaged by Android platform team
    P2Important issues not at the top of the work list
    on Sep 1, 2026
  4. self-assigned this
    on Sep 1, 2026
  5. mboetger commented on Sep 14, 2026

    @mboetger
    Contributor
  6. github-actions commented on Sep 28, 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.

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

Metadata

Metadata

Assignees

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: file_selectorThe file_selector pluginpackageflutter/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