Magic

Magic

190k Downloads

ConcurrentModificationException when iterating over item keys

killme opened this issue ยท 2 comments

commented

The following exception is thrown while walking over the result of getItemKeys and accessing the items using getItem.

java.util.ConcurrentModificationException: null
        at java.util.HashMap$HashIterator.nextNode(HashMap.java:1429) ~[?:1.8.0_91]
        at java.util.HashMap$KeyIterator.next(HashMap.java:1453) ~[?:1.8.0_91]

Code sample:

for (String key : magic.getController().getItemKeys()) {
    // This probably creates some internal structure for the key
    // but it shouldn't, as it is a previously defined item key
    ItemData item = magic.getController().getItem(key);
    if (item == null) {
        // As an additional issue, this returns null occasionally when it shouldn't?
        continue;
    }

    item.getCategories(); // Probably not related
}
commented

I think the most recent dev build should have this fixed, by way of not allowing null values in the ItemController map.

It does seem like there is some other weird issue going on with why those nulls were in there in the first place, though. Hopefully the new warnings may help us track that down.

commented

I tested it and it is working properly now