Fix #3 ArrayIndexOutOfBoundsException#4
Open
Taskeren wants to merge 1 commit into
Open
Conversation
…elements when size equals to tags.length
Glavo
reviewed
Jun 10, 2026
Glavo
left a comment
Member
There was a problem hiding this comment.
本审查建议由 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); |
Member
There was a problem hiding this comment.
本审查建议由 GPT-5 生成
[P1] removeTagFromArray 仍按 size 计算 System.arraycopy 长度,但 ParentTag 注释明确允许 ArrayTag 的 tags.length 小于 size。例如 new IntArrayTag(new int[20]).getTag(1); removeTagAt(1); 时,size == 20、tags.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 的删除场景。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #3 throwing ArrayIndexOutOfBoundsException when removing elements when size equals to tags.length