Skip to content

LinkedCaseInsensitiveMap doesn't override HashMap.clone() [SPR-14509] #19078

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 6459559, dd65f7a, e8562bb, dadd2c3

Backported to: 4.2.8, 3.2.18

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions