epoxy: IndexOutOfBoundsException in EpoxyModelGroup binding

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

About this issue

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

Most upvoted comments

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