I have the following code:
Map<String, List<String>> map;
for(String k : map.keySet()){
List<String> list = map.get(k);
boolean empty = list.isEmpty();
if(!empty && somecheck(k, ...)){
list.clear();
}
}
And I get ConcurrentModificationExceptionin the isEmpty () method. The list is this ArrayList. There is no other list of thread changes because it was created in this method before (and the whole map too). The only modified place list is clear(), but it is called after isEmpty (), and the loop cannot run twice in the same list.
I am using java 1.7
java.util.ConcurrentModificationException
at java.util.ArrayList$SubList.checkForComodification(ArrayList.java:1169)
at java.util.ArrayList$SubList.size(ArrayList.java:998)
at java.util.AbstractCollection.isEmpty(AbstractCollection.java:86)
source
share