Closed
Description
Richard Browne opened SPR-14509 and commented
LinkedCaseInsensitiveMap derives from HashMap, but it does not override the clone() method. As a result, if you clone() a LinkedCaseInsensitiveMap, then subsequently modify the clone, the original can become corrupt.
Here is a test program to illustrate:
public class Test
{
public static void main(String[] args)
{
LinkedCaseInsensitiveMap<String> map1 = new LinkedCaseInsensitiveMap<>();
map1.put("KEY", "FOO");
LinkedCaseInsensitiveMap<String> map2 = (LinkedCaseInsensitiveMap<String>)map1.clone();
map2.put("Key", "Foo");
String value = map1.get("KEY");
System.err.format("Got '%s', expected 'FOO' .. ", value);
System.err.println("FOO".equals(value) ? "SUCCESS" : "FAIL!");
}
}
The map1.get("KEY") line should return "FOO". But instead it returns null.
Affects: 3.2.17, 4.2.7, 4.3.1
Issue Links:
- LinkedCaseInsensitiveMap doesn't implement getOrDefault properly [SPR-13981] #18553 LinkedCaseInsensitiveMap doesn't implement getOrDefault properly
- LinkedCaseInsensitiveMap does not properly support Java 8's merge() and compute() methods [SPR-15026] #19593 LinkedCaseInsensitiveMap does not properly support Java 8's merge() and compute() methods