Skip to content

🐞 Bug Report: KeyItem.getShareTag throws NPE / ArrayIndexOutOfBoundsException #402

@xparadise95

Description

@xparadise95
Component Version
Minecraft 1.20.1
Forge 47.3.0
Treasure² 1.20.1‑3.11.1
ModernFix Default (mixin.perf.nbt_memory_usage = true)
Lithium 0.11.2
PacketFixer 1.1.0
OS Debian Linux (dedicated server)

Image

Image

https://mclo.gs/o0Q0EzF

When the server attempts to sync a Treasure² KeyItem (for example by opening an inventory or Refined Storage grid containing one), it crashes with either an ArrayIndexOutOfBoundsException or a NullPointerException originating in KeyItem.getShareTag(...). This disconnects all players holding that key.

Reproduction Steps
Start a Forge 1.20.1 server with Treasure² v3.11.1 (plus ModernFix, Lithium, PacketFixer).

Acquire or generate a Treasure² Key (the corruption appears after an update).

Put that key into a player’s inventory or place it inside a Refined Storage network.

Open the player inventory or open the Refined Storage GUI.

→ The server immediately prints a stack trace and forcibly disconnects the playe

ArrayIndexOutOfBoundsException:
java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 3
at it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap.rehash(Object2ObjectOpenHashMap.java:1270)
at net.minecraft.nbt.CompoundTag.merge(CompoundTag.java:172)
at mod.gottsch.forge.treasure2.core.item.KeyItem.getShareTag(KeyItem.java:170)
… (packet encoding) …

NullPointerException:
java.lang.NullPointerException: Cannot invoke “net.minecraft.nbt.CompoundTag.getString(String)” because “tag” is null
at mod.gottsch.forge.treasure2.core.item.KeyItem.getShareTag(KeyItem.java:170)
… (packet encoding) …

Both errors originate from KeyItem.getShareTag(...) producing invalid or null NBT data. That invalid tag is then serialized by Minecraft’s packet encoder, causing the server crash.

Suggested Fix:
In KeyItem.getShareTag():
Check for itemStack.getTag() == null before merging.
Create a new empty CompoundTag if needed.
Avoid using FastUtil rehash without validating index bounds.

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions