material-components / material-components/material-components-android
[BottomSheetBehavior] ArrayIndexOutOfBoundsException onLayoutChild()
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
I'm getting the following stack trace in production builds, coming out to around 300-400 instances per month.
Fatal Exception: java.lang.ArrayIndexOutOfBoundsException: length=15; index=15
at java.util.ArrayList.get(ArrayList.java:439)
at com.google.android.material.bottomsheet.BottomSheetBehavior.onLayoutChild(BottomSheetBehavior.java:590)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:918)
at android.view.View.layout(View.java:23411)
at android.view.ViewGroup.layout(ViewGroup.java:6534)
at androidx.drawerlayout.widget.DrawerLayout.onLayout(DrawerLayout.java:1263)
at android.view.View.layout(View.java:23411)
at android.view.ViewGroup.layout(ViewGroup.java:6534)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:23411)
at android.view.ViewGroup.layout(ViewGroup.java:6534)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
at android.view.View.layout(View.java:23411)
at android.view.ViewGroup.layout(ViewGroup.java:6534)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at android.view.View.layout(View.java:23411)
at android.view.ViewGroup.layout(ViewGroup.java:6534)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
at android.view.View.layout(View.java:23411)
at android.view.ViewGroup.layout(ViewGroup.java:6534)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:804)
at android.view.View.layout(View.java:23411)
at android.view.ViewGroup.layout(ViewGroup.java:6534)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3714)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3172)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2141)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8647)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1034)
at android.view.Choreographer.doCallbacks(Choreographer.java:858)
at android.view.Choreographer.doFrame(Choreographer.java:789)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1019)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8097)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
It looks like there might be a race condition where the size of the callbacks array is reduced while iterating through the list.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at BottomSheetBehavior.java near the referenced line and the onLayoutChild() stack frame, then inspect how the callbacks list is iterated and changed. Reproduce or add coverage for the reported length=15, index=15 failure, and verify that callback updates no longer cause an ArrayIndexOutOfBoundsException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100