NBT-API

NBT-API

98.9k Downloads

clearNBT() function giving ConcurrentModificationException

blubbarbs opened this issue ยท 1 comments

commented

I was trying to clear an NBT compound for my plugin and I kept getting ConcurrentModificationExceptions, so I decided to make a quick command to make sure it wasn't me. The command does this:

NBTContainer test = new NBTContainer();

test.setString("test", "t");
test.setInteger("test2", 1);
test.addCompound("test3");
test.clearNBT();

However, when the command is run, I get a ConcurrentModificationException at the clearNBT() line. Attached is the log for that. I am using this API for the commands, which includes this NBT API as a shaded jar. However, my plugin does not use this and has this version of the API as a maven dependency.

Some additional info is that replacing the clearNBT() function call with a loop going through all of the keys and deleting them gives the same result. However, copying the keys into a new collection and deleting them after iterating through that collection does not give the error, so I feel like this is probably an easy fix.

EDIT: I tested the above code after removing the command API as a dependency, and the error above still happens.

commented

Ahhhhhh craaaap I think I know what's going on.

That list seems to be linked deep down to the nbt internals, instead of being a copy. On items this was fine, but for NBTContainers it causes the ConcurrentModificationExceptions. Will be fixed in the 2.11.x release.