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

Aperta Adatta ai principianti
#6,982 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
android, kotlin
Ambito
mobile

Direzione di ricerca

Apri MediaGalleryPreviewActivity.kt ed esamina le letture tipizzate di Parcelable di Intent e Bundle descritte nel report. Confronta la loro gestione dei livelli API con IntentCompat.getParcelableExtra e BundleCompat.getParcelable, quindi verifica il comportamento di compatibilità di AndroidX per API 33. L’issue è risolta quando l’anteprima si apre su Android 13 senza l’arresto anomalo segnalato e le letture dello stato salvato usano getter compatibili.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Kotlin
Stelle
1.7k
Fork
321
Merge medio
19h 57m
PR unite (30g)
167

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di GetStream/stream-chat-android

Tutte le issue di GetStream/stream-chat-android

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.