Skip to content

Conversation

@TerryTaoYY
Copy link

Summary

Align LinkedCaseInsensitiveMap’s entrySet() view with the map’s case-insensitive key contract by making entrySet().contains(..) and entrySet().remove(..) perform case-insensitive key resolution.

Background

LinkedCaseInsensitiveMap provides case-insensitive behavior for containsKey/get/remove. However, entrySet() operations previously delegated to the backing map’s entry set, which performs case-sensitive key comparisons. As a result, entry-based operations could miss existing mappings when callers used different key casing.

Example

LinkedCaseInsensitiveMap<String> map = new LinkedCaseInsensitiveMap<>();
map.put("Key", "value");

assertThat(map.containsKey("KEY")).isTrue();
assertThat(map.entrySet()).contains(Map.entry("KEY", "value")); // previously failed
assertThat(map.entrySet().remove(Map.entry("key", "value"))).isTrue();
assertThat(map).isEmpty();

Changes

  • Implement case-insensitive key lookup for EntrySet.contains(Object) and EntrySet.remove(Object) via containsKey/get/remove
  • Preserve Map.Entry semantics by requiring value equality (using ObjectUtils.nullSafeEquals) before removing

Tests

  • ./gradlew :spring-core:test --tests org.springframework.util.LinkedCaseInsensitiveMapTests
  • ./gradlew :spring-core:test

Signed-off-by: Terry Tao <yueyang.tao@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 19, 2025
@bclozel bclozel self-assigned this Dec 20, 2025
@bclozel bclozel added the in: core Issues in core modules (aop, beans, core, context, expression) label Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core Issues in core modules (aop, beans, core, context, expression) status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants