Skip to content

[file_selector] Handle a null stream from openInputStream on Android - #12683

Closed
ralatorre wants to merge 1 commit into
flutter:mainfrom
ralatorre:file-selector-android-null-stream
Closed

ralatorre wants to merge 1 commit into
flutter:mainfrom
ralatorre:file-selector-android-null-stream

Conversation

@ralatorre

Copy link
Copy Markdown

ContentResolver#openInputStream() returns null when the provider cannot serve the selected file (for example after the provider process crashed). FileSelectorApiImpl#toFileResponse opens the stream in a try-with-resources (where a null resource is legal) and hands it to DataInputStream#readFully, which dereferences it; because toFileResponse runs inside the onActivityResult listener, the NullPointerException surfaces on the main thread and kills the app. 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 (flutter/flutter#191988); #159568 covered a copy failure in the same callback, but not a null stream.

toFileResponse now returns null for a null stream, so the caller completes the callback with the existing "Failed to read file" error instead of crashing, and getPathFromCopyOfFileFromUri reports the condition as the IOException its contract already declares. Two unit tests in the shape of the existing #159568 regression tests, one of them also asserting the read is never attempted.

Fixes flutter/flutter#191989

Pre-Review Checklist

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2

`ContentResolver#openInputStream()` returns null when the provider
cannot serve the file (for example after the provider crashed).
`FileSelectorApiImpl#toFileResponse` handed that null to
`DataInputStream#readFully` on the activity-result callback, so the
NullPointerException surfaced on the main thread and killed the app.
Complete the callback with the existing "Failed to read file" error
instead, and make `FileUtils.getPathFromCopyOfFileFromUri` report the
same condition as the IOException its contract already declares.
@google-cla

google-cla Bot commented Aug 28, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ralatorre

Copy link
Copy Markdown
Author

Closing: I can't complete the CLA at this time. The analysis stays in the linked issue for anyone who wants to pick this up.

@ralatorre ralatorre closed this Aug 28, 2026
@ralatorre
ralatorre deleted the file-selector-android-null-stream branch August 28, 2026 22:25
auto-submit Bot pushed a commit that referenced this pull request Sep 10, 2026
…2716)

Null safety when ContentResolver cannot open a stream. 

Copied from closed: #12683

Fixes: #191989

## Pre-Review Checklist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant