CymChad / CymChad/BaseRecyclerViewAdapterHelper
setDiffNewData异步diff数据时,可能导致IndexOutOfBoundsException
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 24.6k
- Forks
- 5.2k
- PR merge metrics
- No merged PRs in 30d
Description
局部刷新时, 使用#setDiffNewData异步diff数据,此时在RecyclerView中下拉刷新(在BrvahAsyncDiffer进行异步diff的同时),会加载更早的数据,直接使用 getData().addAll(0, earlierDataList),可能导致IndexOutOfBoundsException。
2022-01-07 13:44:14.986, E/WTag-CrashHandler, java.lang.IndexOutOfBoundsException: Index: 4, Size: 40
at java.util.ArrayList.get(ArrayList.java:437)
at com.chad.library.adapter.base.diff.BrvahAsyncDiffer$submitList$1$result$1.areItemsTheSame(BrvahAsyncDiffer.kt:138)
at androidx.recyclerview.widget.DiffUtil.forward(DiffUtil.java:239)
at androidx.recyclerview.widget.DiffUtil.midPoint(DiffUtil.java:198)
at androidx.recyclerview.widget.DiffUtil.calculateDiff(DiffUtil.java:146)
at androidx.recyclerview.widget.DiffUtil.calculateDiff(DiffUtil.java:106)
at com.chad.library.adapter.base.diff.BrvahAsyncDiffer$submitList$1.run(BrvahAsyncDiffer.kt:128)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:929)
getData().addAll(0, earlierDataList)这个操作对数据源进行了更改,使得BrvahAsyncDiffer#submitList中的val oldList: List<T> = adapter.data 这个oldList数据发生了变化。
但是目前的场景,就是需要在已有数据之前添加earlierDataList,有其他方法吗?(不想整个替换数据源)
Contributor guide
No contributing guide indexed for this repository
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 in BrvahAsyncDiffer.kt at submitList, especially the oldList capture and areItemsTheSame call around lines 128 and 138. Reproduce an asynchronous #setDiffNewData operation while prepending data with getData().addAll(0, earlierDataList). Done means the concurrent prepend no longer causes IndexOutOfBoundsException while preserving the requested earlier items.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100