-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
None
-
beta2
-
generic
-
generic
-
Verified
Due to internal details of the Iterator returned by IdentityHashMap.entrySet().iterator(), the toArray method in question will contain size() identical object references to a non-functional Map.Entry. Any attempt to use the Entry will throw an Index out of bounds error. The following program should generate no output and exit normally:
import java.util.*;
public class ToArray {
public static void main(String[] args) {
Map m = new IdentityHashMap();
m.put("french", "connection");
m.put("polish", "sausage");
Object[] mArray = m.entrySet().toArray();
if (mArray[0] == mArray[1])
System.out.println("Broken");
// Calls toString on mArray[0], which throws IndexOutOfBoundsException
mArray[0].toString();
}
}
Instead it prints "broken" and throws an IndexOutOfBoundsException.
import java.util.*;
public class ToArray {
public static void main(String[] args) {
Map m = new IdentityHashMap();
m.put("french", "connection");
m.put("polish", "sausage");
Object[] mArray = m.entrySet().toArray();
if (mArray[0] == mArray[1])
System.out.println("Broken");
// Calls toString on mArray[0], which throws IndexOutOfBoundsException
mArray[0].toString();
}
}
Instead it prints "broken" and throws an IndexOutOfBoundsException.