CymChad / CymChad/BaseRecyclerViewAdapterHelper

BaseNodeAdapter removeNodesAt 这个函数是我调用不对才出现越界吗?

Open
#3,360 0 comments 3 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
}

问题描述:position我传的0,此时data.size = 1。val node = this.data[position]这句出错,因为在这之前this.data.removeAt(position)已经删除data里唯一的数据。

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 inspecting BaseNodeAdapter.removeNodesAt and the call that passes position 0, then reproduce the case where data contains one item. Confirm that removing the final item does not cause an out-of-bounds access, and run the relevant adapter tests or add a regression test if the repository has coverage for this path.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
mobile
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.