JD.CONCUR

JD.CONCUR is found when an iterator is created for collection A, then something is removed from the collection, but the loop is not stopped. For more information seeConcurrentModificationException

Vulnerability and risk

On the following invocation of the "next" method, the code will throw a ConcurrentModificationException.

Mitigation and prevention

An object under iteration cannot be modified. Elements for removal have to be stored in another collection and removed later, or the collection can be cloned and the iterator used on the cloned version.

Example 1

Copy
     void fixList(Collection col) {
         for (Iterator iter = col.iterator(); iter.hasNext();) {
             String el = (String) iter.next();
             if (el.startsWith("/")) {
                 col.remove(el);
             }
         }
     }

JD.CONCUR is reported for line 14: Possible 'ConcurrentModificationException' can be thrown by method 'iter.next()' while iterating over 'col'. You cannot remove a collection element while iterating over the same collection.