Consider the following Java source:
if( agents != null ) { for( Iterator iter = agents.keySet().iterator(); iter.hasNext(); ) { // Code that uses iter.
Make sure you don't set the iter to null inside the loop.
iter