Bug 31861 - IdentityHashMap$IdentityIterator.next() throws ArrayIndexOutOfBoundsException after calling remove()
Summary: IdentityHashMap$IdentityIterator.next() throws ArrayIndexOutOfBoundsException...
Status: UNCONFIRMED
Alias: None
Product: classpath
Classification: Unclassified
Component: classpath (show other bugs)
Version: unspecified
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-08 07:30 UTC by Jeroen Frijters
Modified: 2007-05-08 07:30 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeroen Frijters 2007-05-08 07:30:18 UTC
The following code throws an ArrayIndexOutOfBoundsException, because remove disturbes the iterator state.

import java.util.*;

public class test
{
  public static void main(String[] args) throws Exception
  {
    IdentityHashMap m = new IdentityHashMap();
    for(int i = 0; i < 10; i++)
    {
      m.put("foo" + i, "bar" + i);
    }
    Iterator iter = m.values().iterator();
    while(iter.hasNext())
    {
      System.out.println(iter.next());
      iter.remove();
    }
  }
}