ArrayIndexOutOfBoundsException due to potential thread-unsafe access in Folia #385

Closed
opened 2025-07-27 18:38:52 +02:00 by Blurmit · 3 comments
Blurmit commented 2025-07-27 18:38:52 +02:00 (Migrated from github.com)

Stack trace

[12:44:28] [Region Scheduler Thread #10/ERROR]: Failed to handle packet net.minecraft.network.protocol.game.ServerboundContainerClosePacket@1b2e8eca, suppressing error
java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 10
	at java.base/java.util.ArrayList.add(ArrayList.java:484) ~[?:?]
	at java.base/java.util.ArrayList.add(ArrayList.java:496) ~[?:?]
	at net.minecraft.world.inventory.TransientCraftingContainer.onOpen(TransientCraftingContainer.java:30) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.world.inventory.AbstractContainerMenu.transferTo(AbstractContainerMenu.java:76) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at org.bukkit.craftbukkit.event.CraftEventFactory.handleInventoryCloseEvent(CraftEventFactory.java:1465) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.server.network.ServerGamePacketListenerImpl.handleContainerClose(ServerGamePacketListenerImpl.java:2983) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.server.network.ServerGamePacketListenerImpl.handleContainerClose(ServerGamePacketListenerImpl.java:2975) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.network.protocol.game.ServerboundContainerClosePacket.handle(ServerboundContainerClosePacket.java:33) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.network.protocol.game.ServerboundContainerClosePacket.handle(ServerboundContainerClosePacket.java:8) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$1(PacketUtils.java:31) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.server.level.ServerPlayer.lambda$queuePacketTask$3(ServerPlayer.java:610) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at io.papermc.paper.threadedregions.EntityScheduler.executeTick(EntityScheduler.java:181) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1656) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at io.papermc.paper.threadedregions.TickRegions$ConcreteRegionTickHandle.tickRegion(TickRegions.java:407) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at io.papermc.paper.threadedregions.TickRegionScheduler$RegionScheduleHandle.runTick(TickRegionScheduler.java:418) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9]
	at ca.spottedleaf.concurrentutil.scheduler.SchedulerThreadPool$TickThreadRunner.run(SchedulerThreadPool.java:546) ~[concurrentutil-0.0.3.jar:?]
	at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]

Plugin and Datapack List

[16:18:28 INFO]: ℹ Server Plugins (10):
[16:18:28 INFO]: Paper Plugins (1):
[16:18:28 INFO]:  - CrazyCrates
[16:18:28 INFO]: Bukkit Plugins (9):
[16:18:28 INFO]:  - AnarchyExploitFixes, TradeMe, Vault, ViaBackwards, ViaRewind, ViaVersion, Votifier, WorldEdit, WorldGuard

No datapacks.

Actions to reproduce (if known)

I wasn’t online when it happened, so I don’t know the exact cause. The error suggests the inventory was closed twice concurrently on separate threads, likely causing a race condition.

Folia version

> version
[16:12:38 INFO]: This server is running Folia version 1.21.6-DEV-ver/1.21.6@e4b0ae9 (1970-01-01T00:00:00Z) (Implementing API version 1.21.6-R0.1-SNAPSHOT)
You are running the latest version
Previous version: 1.21.1-DEV-2e7bc07 (MC: 1.21.1)

Other

The user who caused the error said that they were possibly in a trade menu at the time (custom inventory from the TradeMe plugin). Not sure how helpful that is.

### Stack trace ``` [12:44:28] [Region Scheduler Thread #10/ERROR]: Failed to handle packet net.minecraft.network.protocol.game.ServerboundContainerClosePacket@1b2e8eca, suppressing error java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 10 at java.base/java.util.ArrayList.add(ArrayList.java:484) ~[?:?] at java.base/java.util.ArrayList.add(ArrayList.java:496) ~[?:?] at net.minecraft.world.inventory.TransientCraftingContainer.onOpen(TransientCraftingContainer.java:30) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9] at net.minecraft.world.inventory.AbstractContainerMenu.transferTo(AbstractContainerMenu.java:76) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9] at org.bukkit.craftbukkit.event.CraftEventFactory.handleInventoryCloseEvent(CraftEventFactory.java:1465) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9] at net.minecraft.server.network.ServerGamePacketListenerImpl.handleContainerClose(ServerGamePacketListenerImpl.java:2983) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9] at net.minecraft.server.network.ServerGamePacketListenerImpl.handleContainerClose(ServerGamePacketListenerImpl.java:2975) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9] at net.minecraft.network.protocol.game.ServerboundContainerClosePacket.handle(ServerboundContainerClosePacket.java:33) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9] at net.minecraft.network.protocol.game.ServerboundContainerClosePacket.handle(ServerboundContainerClosePacket.java:8) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9] at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$1(PacketUtils.java:31) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9] at net.minecraft.server.level.ServerPlayer.lambda$queuePacketTask$3(ServerPlayer.java:610) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9] at io.papermc.paper.threadedregions.EntityScheduler.executeTick(EntityScheduler.java:181) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9] at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1656) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9] at io.papermc.paper.threadedregions.TickRegions$ConcreteRegionTickHandle.tickRegion(TickRegions.java:407) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9] at io.papermc.paper.threadedregions.TickRegionScheduler$RegionScheduleHandle.runTick(TickRegionScheduler.java:418) ~[folia-1.21.6.jar:1.21.6-DEV-e4b0ae9] at ca.spottedleaf.concurrentutil.scheduler.SchedulerThreadPool$TickThreadRunner.run(SchedulerThreadPool.java:546) ~[concurrentutil-0.0.3.jar:?] at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?] ``` ### Plugin and Datapack List ``` [16:18:28 INFO]: ℹ Server Plugins (10): [16:18:28 INFO]: Paper Plugins (1): [16:18:28 INFO]: - CrazyCrates [16:18:28 INFO]: Bukkit Plugins (9): [16:18:28 INFO]: - AnarchyExploitFixes, TradeMe, Vault, ViaBackwards, ViaRewind, ViaVersion, Votifier, WorldEdit, WorldGuard ``` No datapacks. ### Actions to reproduce (if known) I wasn’t online when it happened, so I don’t know the exact cause. The error suggests the inventory was closed twice concurrently on separate threads, likely causing a race condition. ### Folia version ``` > version [16:12:38 INFO]: This server is running Folia version 1.21.6-DEV-ver/1.21.6@e4b0ae9 (1970-01-01T00:00:00Z) (Implementing API version 1.21.6-R0.1-SNAPSHOT) You are running the latest version Previous version: 1.21.1-DEV-2e7bc07 (MC: 1.21.1) ``` ### Other The user who caused the error said that they were possibly in a trade menu at the time (custom inventory from the TradeMe plugin). Not sure how helpful that is.
Euphillya commented 2025-07-27 20:14:31 +02:00 (Migrated from github.com)

You are using an old version

You are using an old version
Blurmit commented 2025-07-27 21:06:14 +02:00 (Migrated from github.com)

Correct, but this has not been fixed in 1.21.7 or .8, so I feel like this issue remains relevant

Correct, but this has not been fixed in 1.21.7 or .8, so I feel like this issue remains relevant
electronicboy commented 2025-07-27 22:51:04 +02:00 (Migrated from github.com)

I feel that this just goes into the general premise of not sharing local state across contexts, I don't think that there will be much interest in trying to protect this specific backing collection when the entire inventory system is really not designed for concurrent access. This is likely an issue for plugins to resolve

I feel that this just goes into the general premise of not sharing local state across contexts, I don't think that there will be much interest in trying to protect this specific backing collection when the entire inventory system is really not designed for concurrent access. This is likely an issue for plugins to resolve
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Minecraft/Folia#385
No description provided.