bug(splash-screen): SplashScreen.hide() removes the pre-draw listener off the main thread and can crash with IndexOutOfBoundsException on Android
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
- 78/100
Direzione di ricerca
Leggi SplashScreenPlugin.java e SplashScreen.java, concentrandoti sul ramo della schermata di avvio di Android 12 in hide e su come show e hideDialog inviano il lavoro al thread dell’interfaccia utente. Riproduci la rimozione del listener da un thread diverso da quello principale oppure tracciane il flusso. Verifica poi che il percorso di hide rimuova il listener di pre-draw sul thread principale e risolva la chiamata in seguito.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug Report
Plugin(s)
@capacitor/splash-screen 8.0.2 (also present in 8.0.3-nightly-20261127T150834.0 and 9.0.0-alpha.2)
Capacitor Version
@capacitor/core: 8.6.0
@capacitor/android: 8.6.0
@capacitor/splash-screen: 8.0.2
Platform(s)
Android
Current Behavior
Calling SplashScreen.hide() from JavaScript while the launch splash is shown with the Android 12 API (launchAutoHide: true, no dialog) can crash the app:
java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1
at java.util.ArrayList.get (ArrayList.java:435)
at android.view.ViewTreeObserver$CopyOnWriteArray$Access.get (ViewTreeObserver.java:1367)
at android.view.ViewTreeObserver.dispatchOnPreDraw (ViewTreeObserver.java:1175)
at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:4206)
at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:2758)
at android.view.Choreographer.doFrame (Choreographer.java:994)
SplashScreenPlugin.hide(PluginCall) calls splashScreen.hide(...) directly. Plugin methods run on the CapacitorPlugins handler thread (Bridge.callPluginMethod posts to taskHandler), so SplashScreen.hide(int, boolean) reaches content.getViewTreeObserver().removeOnPreDrawListener(this.onPreDrawListener) off the main thread. The pre-draw listener returns false on every frame while the splash is visible, so the main thread keeps dispatching pre-draw listeners. A removal from the plugin thread between CopyOnWriteArray.start() and get(1) produces the exception above. The same removal in the launch auto-hide path runs on the main thread (new Handler(context.getMainLooper()).postDelayed(...)) and is safe.
hideDialog, show and the non-launch hide path already post to the UI thread (activity.runOnUiThread / mainHandler.post); only the Android 12 launch-splash branch of hide does not.
Expected Behavior
SplashScreen.hide() removes the pre-draw listener on the main thread and never races the view traversal.
Code Reproduction
The crash is a timing race, so a sample app reproduces it only intermittently: an app with launchAutoHide: true and a long launchShowDuration that calls SplashScreen.hide() as soon as its first page paints. We saw it in production on 6 users over 28 days (Samsung devices, Android 14 to 17). The thread analysis above is from reading 8.0.2's SplashScreenPlugin.java and SplashScreen.java.
Other Technical Details
The fix we ship as a patch:
@PluginMethod
public void hide(PluginCall call) {
- if (config.isUsingDialog()) {
- splashScreen.hideDialog(getActivity());
- } else {
- splashScreen.hide(getSettings(call));
- }
- call.resolve();
+ getActivity()
+ .runOnUiThread(() -> {
+ if (config.isUsingDialog()) {
+ splashScreen.hideDialog(getActivity());
+ } else {
+ splashScreen.hide(getSettings(call));
+ }
+ call.resolve();
+ });
}
Additional Context
Happy to open a pull request against main with this change if you agree with the approach.
This report was prepared with AI assistance (Claude) on behalf of the app team.
- Lingua principale
- Java
- Stelle
- 688
- Fork
- 690
- Merge medio
- 16h 15m
- PR unite (30g)
- 7
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ionic-team/capacitor-plugins
-
platform: android
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ionic-team/capacitor-plugins#2647 ·
I maintainer di solito rispondono entro 1 giorno
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
ionic-team/capacitor-plugins#2639 ·
I maintainer di solito rispondono entro 1 giorno
-
platform: android
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
ionic-team/capacitor-plugins#2635 ·
I maintainer di solito rispondono entro 1 giorno
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
ionic-team/capacitor-plugins#2627 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ionic-team/capacitor-plugins#2616 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di ionic-team/capacitor-plugins
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
federicoiosue/Omni-Notes#1044 ·
-
Industrial Center Text TypoApertaBug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Terraform releases proxy leaves a temp folder behind on every cache refreshForse già presa @dhananjay6561 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
terrakube-io/terrakube#4069 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno