Following is my code piece:
ArrayList<Contact> contactList = presenter.getContactList();
for (Contact contact : contactList) {
if (null != contact) {
String name = contact.getVehicleNumber();
final ArrayList<Vehicle> vehicleList = contact.getVehicles();
if (vehicleList != null && vehicleList.size() > 0) {
name = vehicleList.get(0).getVehicleNumber();
}
}
}
I am getting java.util.ConcurrentModificationException
.
I have gone through other answers for similar questions but I am not doing any modifications to the original list by adding or removing items. Strange thing is it doesn't happen always.
Will this Exception
occur if presenter.getContactList()
is modified by some other thread while this code piece is executed ?
Stack trace,
12-23 12:08:35.961 24843 25128 E AndroidRuntime: java.util.ConcurrentModificationException
12-23 12:08:35.961 24843 25128 E AndroidRuntime: at java.util.AbstractList$SimpleListIterator.next(AbstractList.java:62)