Blog do projektu Open Source JavaHotel

sobota, 29 stycznia 2011

GWT and java.util.ConcurrentModificationException:

Finally I was able to get rid of very annoying message:


20:34:57.598 [ERROR] [com.mygwt.test] Uncaught exception escaped
java.util.ConcurrentModificationException: null
    at java.util.AbstractList$SimpleListIterator.next(AbstractList.java:64)
    at com.gwtmodel.table.slotmodel.SlotListContainer$GeneralListener.signal(SlotListContainer.java:89)
    at com.gwtmodel.table.slotmodel.SlotListContainer.publish(SlotListContainer.java:126)
    at com.gwtmodel.table.slotmodel.SlotListContainer.publish(SlotListContainer.java:355)
    at com.gwtmodel.table.slotmodel.AbstractSlotContainer.publish(AbstractSlotContainer.java:122)
    at com.mygwt.client.MailOp.access$0(MailOp.java:1)



What more interesting -this message does not seem to make any harm.

It is caused by running through the collection and modifying it from RPC at the same time. The solution was very simple - just walk through the clone of the list, no the list itself.

Instead of:

.........
private final List listOfSubscribers;
........
for (SlotSubscriberType so : llistOfSubscribers) {
  ...
}


just use:

List li = (List) ((ArrayList)listOfSubscribers).clone();
for (SlotSubscriberType so : li) {
...
}


Brak komentarzy:

Prześlij komentarz