Jump to content

[1.16.4] WorldTickEvent Concurrent Access Exception


Recommended Posts

I have a low occurrence issue reported by users of my mod which is resulting in a ConcurrentModificationException. I'm currently trying to investigate some possible options, since I'm having problems duplicating the problem and my understanding of a couple of Minecraft areas is not good.

I've had a look at some of the Minecraft code, but I'm not understanding it well enough to satisfy my theories.


I have a WorldTickEvent handler in my mod, that simply walks a list of block positions using a iter.hasNext loop.

Each loop calls a simple piece of code on the current blockpos and then uses the iter.remove() to remove it from the list.


.....onWorldTick(TickEvent.WorldTickEvent event) .....
.... MultiBlockTracker.run()


public void run() {
Iterator<BlockPos> iter = blocks.iterator();
while (iter.hasNext()) {
    BlockPos pos = iter.next();
    TileEntity te = world.getTileEntity(pos);
    if (te instanceof MultiBlockGlueProvider) {
        ((MultiBlockGlueProvider)te).getGlue().onHello(world, i.getPos());


Each relevant tile entity in my mod can add blocks to this block list via an override of the TileEntity.validate() method.

public void validate() {
    if (!world.isRemote) {

public void addEntry(BlockPos pos) {
    blocks.add(new BlockPos(pos));


The ConcurrentModificationException is pointing at the iter.next.

java.util.ConcurrentModificationException: null
	at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:909) ~[?:1.8.0_181] {}
	at java.util.ArrayList$Itr.next(ArrayList.java:859) ~[?:1.8.0_181] {}
	at ipsis.woot.modules.factory.multiblock.MultiBlockTracker.run(MultiBlockTracker.java:45) ~[woot:1.16.4-] {re:classloading}


As far as I can see I am using the iterator correctly and have used the same pattern successfully(?) elsewhere in my code.

My current guess is that the concurrent modification is because one thread is trying to add to this list, while the other one is trying to remove items from it.


However I'm not sure if this is how Minecraft actually works, because I'm not confident in my understanding of the world tick.


So does anyone know what threads of execution are actually going on here


Can the world tick event and the tile entity validate be running in different threads causing this concurrent access to happen and I need to add some locking around the block list?


Or is there a different thread for each world meaning I could have two WorldTickEvent at the same time therefore I've got two iterators running over the same list removing items at the "same time"?


Or am I just looking at a red herring and the problem actually lies elsewhere?





Link to comment
Share on other sites

That is something I hadn't considered in terms of threads.


I have the WorldTickEvent handler do nothing on the client but run on the server.

I may have some paths for the addEntry running on both the client and server. Something I need to look into and check if that is where the conflict is coming from.



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.