This is unsafe behavior as the iterator that is created by the syntax in not aware of the collection being mutated. See discussion here http://stackoverflow.com/questions/1196586/calling-remove-in-foreach-loop-in-java. I think this would need to be a java code rule to validate that remove is actually being called on the collection being iterated. I tried with just XPath, but you get false positives because you can't correlate the 2 variable names (the one remove is called on and the one in the for loop statement.