-
Bug
-
Resolution: Fixed
-
P3
-
5.0, 6
-
b51
-
generic, x86, sparc
-
generic, solaris_9, windows_xp
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2128547 | 5.0u6 | Martin Buchholz | P3 | Resolved | Fixed | b03 |
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
XP SP2
A DESCRIPTION OF THE PROBLEM :
(inbound IdentityHashMap ip)
int sz = ip.size();
Object [] entries = new Object[sz];
ip.entrySet().toArray(entries);
Entries contains nulls, even though there is room for entries in the given array.
Look at the implementation, we find this:
public <T> T[] toArray(T[] a) {
return (T[])toArray(); // !!!!
}
Seems like it was never implemented, and a placeholder was left.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run code above
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
entries array should contain Map.Entry objects, not nulls.
ACTUAL -
entries array contains only nulls, as it is never written to.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
IdentityHashMap im = new IdentityHashMap();
im.put(im,im);
Object [] o = new Object[1];
im.entrySet().toArray(o);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
never call toArray(object [])
- backported by
-
JDK-2128547 (coll) IdentityHashMap.entrySet().toArray(T[] a) is incorrectly implemented
- Resolved
- duplicates
-
JDK-6316004 IdentityHashMap.EntrySet.toArray(Object[]) is broken
- Closed
- relates to
-
JDK-6310858 (coll) EnumMap.entrySet().toArray(T[] a) is incorrectly implemented
- Closed
-
JDK-6312706 (coll) Map entrySet iterators should return different entries on each call to next()
- Closed
-
JDK-5031890 (coll spec) Collection toArray() does not specify empty collection behavior
- Closed
-
JDK-6232484 (coll) ArrayList made from IdentityHashMap.entrySet() fails to create properly
- Closed