question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IndexOutOfBoundsException in EpoxyModelGroup binding

See original GitHub issue

Hi,

We use EpoxyModelGroup in our app and since then it crash on IndexOutOfBoundsException (see stack-trace below). Unfortunately I cannot publish our code but I will try to repro in a sample app. The crash happen when a model group get updated and when the nested models increase.

It crash on this line in EpoxyModelGroup.java

EpoxyModel<?> previousModel = previousGroup.models.get(modelIndex);` 

Before they were 4 models in the group and after the update there were 11 models.

java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
 	at java.util.ArrayList.get(ArrayList.java:437)
 	at com.airbnb.epoxy.EpoxyModelGroup$3.onModel(EpoxyModelGroup.java:144)
	at com.airbnb.epoxy.EpoxyModelGroup.iterateModels(EpoxyModelGroup.java:197)
 	at com.airbnb.epoxy.EpoxyModelGroup.bind(EpoxyModelGroup.java:139)
 	at com.airbnb.epoxy.EpoxyViewHolder.bind(EpoxyViewHolder.java:57)
	at com.airbnb.epoxy.BaseEpoxyAdapter.onBindViewHolder(BaseEpoxyAdapter.java:97)
 	at com.airbnb.epoxy.EpoxyControllerAdapter.onBindViewHolder(EpoxyControllerAdapter.java:16)
	at com.airbnb.epoxy.BaseEpoxyAdapter.onBindViewHolder(BaseEpoxyAdapter.java:15)
 	at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6823)
 	at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5752)
 	at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6019)
 	at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
 	at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
 	at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
 	at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
	at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
 	at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
 	at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
	at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
 	at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4194)

Using Epoxy 3.2

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
MTRNordcommented, Feb 18, 2019

Hm not sure if the fix affects everything. Because I am able to reproduce a similiar error with 3.3.0 without using ModelGroups 😕

java.lang.IndexOutOfBoundsException: Index out of bounds - passed position = 30, old list size = 30
    at androidx.recyclerview.widget.DiffUtil$DiffResult.convertOldPositionToNew(DiffUtil.java:672)
    at androidx.paging.PagedStorageDiffHelper.transformAnchorIndex(PagedStorageDiffHelper.java:215)
    at androidx.paging.AsyncPagedListDiffer.latchPagedList(AsyncPagedListDiffer.java:382)
    at androidx.paging.AsyncPagedListDiffer$2$1.run(AsyncPagedListDiffer.java:345)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6798)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

It happens when scrolling too fast

0reactions
ahmed-alnaamicommented, Aug 25, 2019

hi, I faced the same issue and had a workaround while using the placeholders (they are very important for smooth scrolling) stack overflow answer , see update 2 of that answer

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix IndexOutOfBoundsException in RecyclerView ...
My app uses "Jetpack Navigation, DataBinding, ViewModel". A Fragment has RecyclerView. If I touch one of the items, it is navigated to B ......
Read more >
EpoxyModel.getSpanSizeInternal - airbnb/epoxy - Tabnine
Defaults to using the span size of the first model. Override this if you need to customize it return models.get(0).getSpanSizeInternal(totalSpanCount ...
Read more >
ModelList.java example - Javatips.net
This class describes the usage of ModelList.java.
Read more >
How to use ViewBinding for EpoxyModelGroup? - Airbnb/Epoxy
Issue Title Created Date Comment Count Updated Date Mermaid format export not possible from the UI 1 2022‑04‑10 2022‑10‑12 Un‑support Utf‑8 Chinese words. 5 2022‑07‑11...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found