-
Notifications
You must be signed in to change notification settings - Fork 781
Open
Description
Original issue created by danesh@google.com on 2013-02-28 at 06:54 PM
If you have a loop over a Collection and are modifying the collection within the loop. Currently it will throw a ConcurrentModificationException which is a run-time exception. Ideally this should be caught at compile-time.
Bad example:
ArrayList<Item> itemList = //...
for (Item item : itemList) {
if (someCondition) {
itemList.remove(item); // Exception thrown here
}
}
If someCondition is a rareCondition, then this bug may not be discovered unless sufficiently unit tested and/or until the code hits the rareCondition (which depending on the rarity of the condition, could take a while).
Good example:
Use an Iterator with an Iterator.remove();
Reactions are currently unavailable