Skip to content

Fix case-insensitive remove in LinkedCaseInsensitiveMap views - #37607

Open
guanchengang wants to merge 1 commit into
spring-projects:mainfrom
guanchengang:fix/linked-case-insensitive-map-view-remove
Open

guanchengang wants to merge 1 commit into
spring-projects:mainfrom
guanchengang:fix/linked-case-insensitive-map-view-remove

Conversation

@guanchengang

Copy link
Copy Markdown
Contributor

KeySet.remove(Object) reported false when the mapped value was null, because it relied on LinkedCaseInsensitiveMap.remove(Object) returning a non-null previous value. Check containsKey(Object) first and delegate the removal to the map.

KeySet.removeAll(Collection) and EntrySet.removeAll(Collection) fell back to AbstractSet.removeAll, which delegates to Collection.contains on the argument when its size is not larger than this set. That check is case-sensitive and also relies on Map.Entry.equals, so keys such as "Key" and "KEY" were not matched and nothing was removed.Delegate to the view's own remove(Object) for every element instead, which is case-insensitive and already handles null values and non-matching element types.

`KeySet.remove(Object)` reported false when the mapped value was null,
because it relied on `LinkedCaseInsensitiveMap.remove(Object)` returning
a non-null previous value. Check `containsKey(Object)` first and delegate
the removal to the map.

`KeySet.removeAll(Collection)` and `EntrySet.removeAll(Collection)` fell
back to `AbstractSet.removeAll`, which delegates to `Collection.contains`
on the argument when its size is not larger than this set. That check
is case-sensitive and also relies on `Map.Entry.equals`, so keys such as
"Key" and "KEY" were not matched and nothing was removed.Delegate to the
view's own `remove(Object)` for every element instead, which is
case-insensitive and already handles null values and non-matching element
types.

Signed-off-by: Chengang Guan <guanchengang@qq.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 30, 2026
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Oct 30, 2026

This branch has not been deployed

No deployments
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