-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8, 11, 17, 21, 25
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
A bug exists in the IdentityHashMap implementation where modifications to a Map.Entry obtained from its entry set do not properly propagate back to the original map, breaking the expected bidirectional relationship between entries and their containing map.
And this result is different with HashMap.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
true
test=initial
test=modified
{test=modified}
test=modified2
{test=modified2}
ACTUAL -
true
test=initial
test=modified
{test=initial}
test=modified
{test=modified2}
---------- BEGIN SOURCE ----------
IdentityHashMap<String, String> mutMap = new IdentityHashMap<>();
mutMap.put("test", "initial");
Map.Entry<String, String> arrayEntry =
(Map.Entry<String, String>) mutMap.entrySet().toArray()[0];
boolean flag = mutMap.entrySet().contains(arrayEntry);
System.out.println(flag);
System.out.println(arrayEntry);
arrayEntry.setValue("modified");
System.out.println(arrayEntry);
System.out.println(mutMap);
mutMap.put("test", "modified2");
System.out.println(arrayEntry);
System.out.println(mutMap);
---------- END SOURCE ----------
A bug exists in the IdentityHashMap implementation where modifications to a Map.Entry obtained from its entry set do not properly propagate back to the original map, breaking the expected bidirectional relationship between entries and their containing map.
And this result is different with HashMap.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
true
test=initial
test=modified
{test=modified}
test=modified2
{test=modified2}
ACTUAL -
true
test=initial
test=modified
{test=initial}
test=modified
{test=modified2}
---------- BEGIN SOURCE ----------
IdentityHashMap<String, String> mutMap = new IdentityHashMap<>();
mutMap.put("test", "initial");
Map.Entry<String, String> arrayEntry =
(Map.Entry<String, String>) mutMap.entrySet().toArray()[0];
boolean flag = mutMap.entrySet().contains(arrayEntry);
System.out.println(flag);
System.out.println(arrayEntry);
arrayEntry.setValue("modified");
System.out.println(arrayEntry);
System.out.println(mutMap);
mutMap.put("test", "modified2");
System.out.println(arrayEntry);
System.out.println(mutMap);
---------- END SOURCE ----------
- relates to
-
JDK-8038146 Clarify Map.Entry's connection to the underlying map
-
- Resolved
-