I have following code: I expected it to throw ConcurrentModificationException but it is working fine. Can some explain the reason? Answer The reason is you are not technically iterating the List. Instead you are random accessing the list using a incrementing index, and removing some values. If you change to code like this to iterate the list it will throw
Tag: concurrentmodification
java.util.ConcurrentModificationException while mutating an object
I am iterating over a List of CustomObject and while doing this iteration, I am mutating this object by adding a tag to tags list of this custom object. I am not adding or removing any CustomObject to or from customObjects (List). I am still getting java.util.ConcurrentModifcationException. Here is the stack trace: Does this mean we can get ConcurrentModifcationException even
Why is a ConcurrentModificationException thrown and how to debug it
I am using a Collection (a HashMap used indirectly by the JPA, it so happens), but apparently randomly the code throws a ConcurrentModificationException. What is causing it and how do I fix this problem? By using some synchronization, perhaps? Here is the full stack-trace: Answer This is not a synchronization problem. This will occur if the underlying collection that is