Skip to content

Crash: IllegalStateException: Must call PhenotypeContext.setContext() when querying file size on Android #460

@mianaliasjad

Description

@mianaliasjad

I’m encountering a rare crash on Android when using FileKit to pick a PDF file and retrieve its size. It affects a very small number of users (1–2 reports), but it still results in a full app crash.

Stack trace excerpt:

Fatal Exception: java.lang.IllegalStateException: Must call PhenotypeContext.setContext() first
    at android.os.Parcel.createException(Parcel.java:2079)
    at android.os.Parcel.readException(Parcel.java:2039)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
    at android.content.ContentProviderProxy.query(ContentProviderNative.java:423)
    at android.content.ContentResolver.query(ContentResolver.java:944)
    at android.content.ContentResolver.query(ContentResolver.java:880)
    at android.content.ContentResolver.query(ContentResolver.java:836)
    at io.github.vinceglb.filekit.PlatformFile_androidKt.getUriFileSize(PlatformFile_android.kt:481)
    at io.github.vinceglb.filekit.PlatformFile_androidKt.size(PlatformFile_android.kt:138)
    at com.test.viewmodels.HomeViewModel$openPdfFilePicker$1.invokeSuspend(HomeViewModel.kt:369)

When selecting a PDF via the file picker, the call to PlatformFile.size() triggers a ContentResolver.query() which fails with the above exception. This results in an immediate app crash.

Environment

FileKit version: 0.12.0

Android version(s): Android 10
Device: Infinix Note 7 Lite

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions