Concurrent Modification when changing maps?

No, it just proves he’s trying to iterate through a list at the same time as adding or removing things to it.
The classic mistake:


		ArrayList<String> strings = new ArrayList<>(Arrays.asList("woops", "this", "is", "wrong"));

		for (String s : strings) {
			if ("wrong".equals(s)) {
				strings.add("kaboom");
			}
		}

Boom! CME.

Cas :slight_smile:

Use a stream?

strings.forEach( Your-Consumer-here );

At least, maybe, use them for the theoretically simple stuff like iterating for a render or update. (Assumes they don’t overlap–which they shouldn’t if you designed things right.)

Also wouldn’t it be nice to be able to just write


ArrayList<String> strings = ["hurrah", "for", "compilers"];

and have it figure out you want to instantiate an ArrayList from that?
While we’re at it


HashMap<String, String> things = ["Don't":"hold", "your":"breath"];

Ho hum.

Cas :slight_smile:

Don’t want to start a war or something, but Groovy has that :wink:

No, when ArrayList.clear() (not remove, not add: clear!!) fails with ConcurrentModificationException, the current thread is not also adding/removing during the clear, hence another thread is, hence the proof.

[quote=“MrPork,post:1,topic:57990”]

I doubt, the CME was raised in clear(). We didn’t see a stacktrace from OP, so I still bet it’s while adding to the itemList…

But ArrayList.clear() cannot throw CME? Only the Iterator methods actually do the throwing - the ArrayList stuff just sets it up to throw next time one of them is called.

Cas :slight_smile:

ArrayList#clear()


/**
 * Removes all of the elements from this list.  The list will
 * be empty after this call returns.
 */
   public void clear() {
        modCount++;

        // clear to let GC do its work
        for (int i = 0; i < size; i++)
            elementData[i] = null;

        size = 0;
}

Riven is the boss.
The boss is always right.
If the boss is really right he’s right even more =>
Riven is right. (Look upward at the code)
This completes the proof.

Btw, I offered something wrong about added/removed lists?

Have I suddenly entered a parallel universe?

Cas :slight_smile:

Nope! He just poked fun of me, given that I failed miserably :slight_smile:

If you told about me, Riven, don’t you think that I’m the rude and impolite guy.

It’s kinda of emotional tsunamy happened indeed. :wink:

I’m sorry. Afterwards I’ll try to be more moderate…

At no point was I even mildly distressed by your remarks :point:

But still! We have not solved OP’s problem.

http://s.mlkshk.com/r/D00U

Cas :slight_smile:

OP doesn’t seem interested anyways…