bug(splash-screen): SplashScreen.hide() removes the pre-draw listener off the main thread and can crash with IndexOutOfBoundsException on Android
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
調査の方向性
SplashScreenPlugin.java と SplashScreen.java を読み、hide 内の Android 12 の起動画面分岐と、show および hideDialog が UI スレッドに処理をディスパッチする方法に注目してください。メインスレッド以外からのリスナー削除を再現するか、その処理を追跡してください。その後、hide の経路でメインスレッド上の pre-draw リスナーが削除され、その後に呼び出しが解決されることを確認してください。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Java
- スター
- 688
- フォーク
- 690
- 平均マージ
- 16時間 15分
- マージ済み PR(30日)
- 7
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ionic-team/capacitor-plugins のほかの issue
-
platform: android
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ionic-team/capacitor-plugins#2647 ·
メンテナーはふだん 1 日以内に返信
-
triage
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
ionic-team/capacitor-plugins#2639 ·
メンテナーはふだん 1 日以内に返信
-
platform: android
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
ionic-team/capacitor-plugins#2635 ·
メンテナーはふだん 1 日以内に返信
-
triage
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
ionic-team/capacitor-plugins#2627 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ionic-team/capacitor-plugins#2616 ·
メンテナーはふだん 1 日以内に返信
ionic-team/capacitor-plugins の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
federicoiosue/Omni-Notes#1044 ·
-
Bug
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
Terraform releases proxy leaves a temp folder behind on every cache refresh対応中かも @dhananjay6561 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
terrakube-io/terrakube#4069 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信