When looping through a List
that comes from a JPA query in WebLogic, the application throws a ConcurrentModificationException
as soon as this list is traversed.
Caused By: java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:909)
at java.util.ArrayList$Itr.next(ArrayList.java:859)
(rest of stack trace omitted)
The pseudo-code looks as follows:
final List<SomeEntity> someEntities = someEntityDao.getAllMatchingSomeCriteria();
for (final SomeEntity someEntity : someEntities ) {
// ...
}
It's important to note that the list someEntities
is not modified in any way, shape or form by the code. Rather, I've come to the conclusion that WebLogic is still filling up the list in a separate thread, while the main thread is already traversing it.
It can be solved as follows:
final List<SomeEntity> someEntities = new ArrayList<>(someEntityDao.getAllMatchingSomeCriteria());
for (final SomeEntity someEntity : someEntities ) {
// ...
}
But that means having to go through all of the code, and that's a last resort. Is there a way to tell WebLogic to stop trying to be clever?