LPS-49297 Preventing the use of an iterator that can be invalidated inside the loop