MediaGalleryPreviewActivity crashes on Android 13: NPE Class.isInterface() in typed getParcelableExtra

Open Beginner friendly
#6,982 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
android, kotlin
Domain
mobile

Research direction

Open MediaGalleryPreviewActivity.kt and inspect the typed Intent and Bundle parcelable reads described in the report. Compare their API level handling with IntentCompat.getParcelableExtra and BundleCompat.getParcelable, then check the AndroidX compatibility behavior for API 33. The issue is done when the preview opens on Android 13 without the reported crash and the saved state reads use compatible getters.

Written by the indexing model from the issue text.

Description

Describe the bug
MediaGalleryPreviewActivity crashes on Android 13 (API 33) while reading its intent extras, with no app code in the stack:

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Class.isInterface()' on a null object reference
  at java.lang.Class.isAssignableFrom(Class.java:874)
  at android.os.Parcel.readParcelableCreatorInternal(Parcel.java:4875)
  at android.os.Parcel.readParcelableInternal(Parcel.java:4788)
  at android.os.Parcel.readValue(Parcel.java:4554)
  at android.os.Parcel.readValue(Parcel.java:4334)
  at android.os.Parcel.-$$Nest$mreadValue(Unknown Source)
  at android.os.Parcel$LazyValue.apply(Parcel.java:4432)
  at android.os.Parcel$LazyValue.apply(Parcel.java:4391)
  at android.os.BaseBundle.getValueAt(BaseBundle.java:394)
  at android.os.BaseBundle.getValue(BaseBundle.java:374)
  at android.os.BaseBundle.getValue(BaseBundle.java:357)
  at android.os.BaseBundle.get(BaseBundle.java:696)
  at android.os.Bundle.getParcelable(Bundle.java:947)
  at android.content.Intent.getParcelableExtra(Intent.java:8930)
  at io.getstream.chat.android.compose.ui.attachments.preview.MediaGalleryPreviewActivity.onCreate$lambda$13(MediaGalleryPreviewActivity.kt)
  at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.kt:122)
  ...

The private helper Intent.getParcelable<T>(key) in MediaGalleryPreviewActivity switches to the typed getParcelableExtra(key, T::class.java) from Build.VERSION_CODES.TIRAMISU. The typed Intent/Bundle getters have a known platform bug on API 33 that throws exactly this NPE inside Parcel.readParcelableCreatorInternal; it is fixed in API 34. That is why androidx.core.content.IntentCompat.getParcelableExtra / BundleCompat.getParcelable only use the typed API from UPSIDE_DOWN_CAKE and fall back to the untyped call on 33.

Suggested fix: replace the helper with IntentCompat.getParcelableExtra(intent, key, T::class.java) (or raise the version check to Build.VERSION_CODES.UPSIDE_DOWN_CAKE). The same pattern applies to the Bundle reads from savedInstanceState.

The file is identical in 7.13.0, 7.18.0 and develop, so the crash is still present in the latest release.

SDK version

  • stream-chat-android-compose 7.13.0 (code unchanged up to 7.18.0 / develop)

To Reproduce
Not reproducible on demand: it is a platform race in the Android 13 typed Parcel API. Observed in production:

  1. Open a channel containing an image attachment
  2. Tap the image to open MediaGalleryPreviewActivity
  3. The activity crashes during the first composition

Expected behavior
The media gallery preview opens without crashing on Android 13.

Device:

  • Vendor and model: Xiaomi Redmi Note 11 (2201117TY)
  • Android version: 13 (TKQ1.221114.001)

Screenshots
N/A

Dominant language
Kotlin
Stars
1.7k
Forks
321
Avg merge
19h 57m
Merged PRs (30d)
167

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from GetStream/stream-chat-android

All issues in GetStream/stream-chat-android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.