CymChad / CymChad/BaseRecyclerViewAdapterHelper

调用BaseNodeAdapter的nodeSetData()和nodeRemoveData()操作列表最后一个条目会崩溃报错

Open
#3,344 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
24.6k
Forks
5.2k
PR merge metrics
No merged PRs in 30d

Description

报错方法:
/**
* 从数组中移除
* @param position Int
* @return Int 被移除的数量
*/
private fun removeNodesAt(position: Int): Int {
if (position >= data.size) {
return 0
}
// 记录被移除的item数量
var removeCount = 0

    // 先移除子项
    removeCount = removeChildAt(position)

    // 移除node自己
    this.data.removeAt(position)
    removeCount += 1

    val node = this.data[position] 
    // 移除脚部
    if (node is NodeFooterImp && node.footerNode != null) {
        this.data.removeAt(position)
        removeCount += 1
    }
    return removeCount
}

image

崩溃日志:
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionBaseViewHolder{4b14998 position=23 id=-1, oldPos=-1, pLpos:-1 no parent} androidx.recyclerview.widget.RecyclerView{a59f2b1 VFED.V... ........ 0,100-720,1363 #7f0a03da app:id/rv_friend}, adapter:com.nn.accelerator.adapter.chat.ChatFriendAdapter@6247396, layout:androidx.recyclerview.widget.LinearLayoutManager@4c11b17, context:com.nn.accelerator.ui.activity.MainActivity@6cdc5f7
at androidx.recyclerview.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:6087)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6270)
at androidx.recyclerview.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:288)
at androidx.recyclerview.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:345)
at androidx.recyclerview.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:361)
at androidx.recyclerview.widget.GapWorker.prefetch(GapWorker.java:368)
at androidx.recyclerview.widget.GapWorker.run(GapWorker.java:399)
at android.os.Handler.handleCallback(Handler.java:914)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:225)
at android.app.ActivityThread.main(ActivityThread.java:7563)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:994)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating removeNodesAt in BaseNodeAdapter and trace calls from nodeSetData() and nodeRemoveData(). Reproduce the failure by removing the final list entry, then verify the list and RecyclerView remain consistent without an IndexOutOfBoundsException.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.