Scyntrus / FactionMobs

FactionMobs CraftBukkit Plugin
http://dev.bukkit.org/server-mods/faction-mobs/
Other
14 stars 19 forks source link

Error in console Task #55 #18

Closed Resoluciones closed 6 years ago

Resoluciones commented 6 years ago

https://hasteb.in/akatovit.rb

Scyntrus commented 6 years ago

What were you doing when this happened? Everything is coded to run synchronously so this should never happen. Are you running some custom version of CB/Spigot?

Resoluciones commented 6 years ago

Hi Scyntrus, I'm not sure unfortunately what originated that eror, I just saw the error in console but I was not online.

I'm running last Paper build, but I didn't notice any change or problem with FM when I replaced the Spigot some months ago.

Sataniel98 commented 6 years ago

ConcurrentModificationExceptions don't only happen in multi threaded environments but also when a collection is modified while iterating. In this case, because something inside this loop adds or removes values from FactionMobs.mobList while iterating over it.

            for (FactionMob fmob : FactionMobs.mobList) {...

Easiest fix would be to make mobList a CopyOnWriteArrayList or to produce a concurrent hash set from a ConcurrentHashMap.

    public static Set<FactionMob> mobList = Collections.newSetFromMap(new ConcurrentHashMap<FactionMob, Object>());
    public static Set<FactionMob> mobList = ConcurrentHashMap.newKeySet(); // I think this is how it's done in Java 8?

Instead, you could find out where the addition / removal of values happens, add them to a new collection outside of the loop and to do the actions after the loop.

Scyntrus commented 6 years ago

I'm aware of that and I already checked that my code doesn't directly modify the Set. However, since the addEntity function broadcasts and Event this error could happen if another plugin force kills the Entity right away.