A: 

This happens when you use for (Object o : array). So my solution is:

for (int i = 0; i < array.length; i++) { ... }
Martijn Courteaux
Well, crap. I am indeed using a for-each loop to iterate over that thing, so you could be on to something. What makes this happen? Is a for-each loop simply a disaster waiting to happen when applied to concurrently accessed data structures?
BlairHippo
It wouldn't be the enhanced for loop idiom that is to blame, but rather the fact that you are iterating over the list while something else is changing it.
matt b
+6  A: 

CopyOnWriteArrayList.subLists throw ConcurrentModificationExceptions if the containing list changes out from underneath it:

public class ListTest {

  private static List<int[]> intList;

  public static void main (String[] args) {
    CopyOnWriteArrayList<Integer> cowal = new CopyOnWriteArrayList<Integer>();
    cowal.add(1);
    cowal.add(2);
    cowal.add(3);

    List<Integer> sub = cowal.subList(1, 2);
    cowal.add(4);
    sub.get(0); //throws ConcurrentModificationException
  }
}
Sbodd
A am indeed making a call to subList, so this could be it. (Hard to tell, as the error is occurring in the field, not on my test rig. Grr.) However, to make that more like my code, I changed "cowal" to a simple "List<Integer>", and didn't bother with the intermediate "sub" variable; I did "cowal = cowal.subList(1, 2);". Under those conditions, the code runs without incident. Is there any other way for a subList() call to cause trouble?
BlairHippo
Why don't you just post the code in question?
matt b
matt b: I would, but too much code and I haven't figured out how to strip it down to where it throws the error. (Yet.) If I come up with a bare-bones version (and the answer DOESN'T jump up and smack me in the face), I'll post it.
BlairHippo
Still haven't precisely replicated the error locally, but I'm 90% sure that subList() is indeed the source of my woe. (See the edited question for details why.) My thanks for getting me pointed in the right direction.
BlairHippo
A: 

Sbodd has the correct answer, but it sounds like using CopyOnWriteArrayList instead of ArrayList is just an attempt to mask the error. The true problem is an attempt to modify the underlying list while iterating over it. You need to find where in your code you are accessing it as such and remove that usage or work around it.

matt b
Except, isn't safely modifying the underlying list while iterating over it CopyOnWriteArrayList's reason for existing?
BlairHippo