Skip to content

Fix #3 ArrayIndexOutOfBoundsException#4

Open
Taskeren wants to merge 1 commit into
HMCL-dev:mainfrom
Taskeren:bugfix-remove
Open

Fix #3 ArrayIndexOutOfBoundsException#4
Taskeren wants to merge 1 commit into
HMCL-dev:mainfrom
Taskeren:bugfix-remove

Conversation

@Taskeren

@Taskeren Taskeren commented Jun 7, 2026

Copy link
Copy Markdown

Fix #3 throwing ArrayIndexOutOfBoundsException when removing elements when size equals to tags.length

…elements when size equals to tags.length

@Glavo Glavo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本审查建议由 GPT-5 生成


已将具体审查建议标注在对应代码行。

int arrayEnd = Math.min(size, tags.length);
if (index < arrayEnd - 1) {
System.arraycopy(tags, index + 1, tags, index, size - index);
System.arraycopy(tags, index + 1, tags, index, size - index - 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本审查建议由 GPT-5 生成


[P1] removeTagFromArray 仍按 size 计算 System.arraycopy 长度,但 ParentTag 注释明确允许 ArrayTagtags.length 小于 size。例如 new IntArrayTag(new int[20]).getTag(1); removeTagAt(1); 时,size == 20tags.length == 12,这里的复制长度为 18,仍会读到 tags 数组边界之外并抛出 ArrayIndexOutOfBoundsException。这里应按 arrayEnd - index - 1 复制,而不是 size - index - 1。否则这个修复只覆盖了 ListTag/CompoundTag 容量等于 size 的场景,ArrayTag.removeAt/removeTagAt/addTag 中移动已缓存子 tag 的路径仍会崩溃。

测试缺口:新增测试只覆盖 ListTag,没有覆盖 ArrayTag 的 lazy cached tags 且 size > tags.length 的删除场景。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ParentTag#removeAt throws ArrayIndexOutOfBoundsException at Specific Sizes

2 participants