Skip to content

[file_selector_android] Attempting to return null paths from FileUtils.java results in an IllegalStateException #159568

Open
@gmackall

Description

@gmackall

FileUtils.java will return a null path in a couple of exception cases:
https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector_android/android/src/main/java/dev/flutter/packages/file_selector_android/FileUtils.java#L139

The idea behind this approach was as an alternative to throwing errors in Java code, which would crash the app (originally in image_picker, these two plugins share much of this code)
flutter/packages#4004

But this approach doesn't actually prevent a crash, because the path is marked as not nullable. The path gets returned
https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector_android/android/src/main/java/dev/flutter/packages/file_selector_android/FileSelectorApiImpl.java#L360
and then the builder will try to set that path on the object, at which point the generated Java object does the following check
https://github.com/flutter/packages/blob/main/packages/file_selector/file_selector_android/android/src/main/java/dev/flutter/packages/file_selector_android/GeneratedFileSelectorApi.java#L77
and throws an IllegalStateException if the path is null.

We should probably switch to surfacing exceptions in dart, following the pattern introduced in flutter/packages#8184.

image_picker is likely also affected, though I haven't checked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: 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