Skip to content

Fix LinkedCaseInsensitiveMap.KeySet.remove() for null values - #37737

Merged
sbrannen merged 3 commits into
spring-projects:mainfrom
SwapnilKachare7:fix/linked-case-insensitive-map-keyset-remove
Nov 21, 2026
Merged

sbrannen merged 3 commits into
spring-projects:mainfrom
SwapnilKachare7:fix/linked-case-insensitive-map-keyset-remove

Conversation

@SwapnilKachare7

Copy link
Copy Markdown
Contributor

Summary

Fixes LinkedCaseInsensitiveMap.KeySet.remove(Object) so that removing an existing key mapped to a null value returns true instead of false.

Cause

Previously, KeySet.remove(Object) checked LinkedCaseInsensitiveMap.this.remove(o) != null. Because Map.remove(key) returns null both when a key is missing and when it is present with a null value, removing an existing key with a null value returned false.

Fix

  • Check containsKey(o) before removing the entry via LinkedCaseInsensitiveMap.this.remove(o) and return true when present (false otherwise).

Verification

  • Ran ./gradlew :spring-core:test --tests "*LinkedCaseInsensitiveMapTests*" locally.

Signed-off-by: Swapnil kachare <swapnilkachare03@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 Nov 21, 2026
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Nov 21, 2026

@sbrannen sbrannen left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, and thanks for the PR!

In the future, please do not add additional blank lines.

Also, PRs like this require a test or tests that fail before the changes and pass after the changes. Note, however, that I will add those tests after merging.

In addition, please note that the commit needs a "body". See our contributing guidelines for examples.

@sbrannen sbrannen self-assigned this Nov 21, 2026
@sbrannen sbrannen added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 21, 2026
@sbrannen sbrannen changed the title Fix LinkedCaseInsensitiveMap.KeySet.remove() for null values Fix LinkedCaseInsensitiveMap.KeySet.remove() for null values Nov 21, 2026
…nsensitiveMap.java

Signed-off-by: Sam Brannen <104798+sbrannen@users.noreply.github.com>
…nsensitiveMap.java

Signed-off-by: Sam Brannen <104798+sbrannen@users.noreply.github.com>
@sbrannen
sbrannen merged commit 9d3ca11 into spring-projects:main Nov 21, 2026
1 check passed
sbrannen added a commit that referenced this pull request Nov 21, 2026
sbrannen pushed a commit that referenced this pull request Nov 21, 2026
Fix LinkedCaseInsensitiveMap.KeySet.remove() for null values

Prior to this commit, LinkedCaseInsensitiveMap.KeySet.remove() returned
false for a key mapped to a null value, even though the entry was
removed. This is because it relied on the return value of
LinkedCaseInsensitiveMap.remove(), which is null for both an absent key
and a key mapped to null.

This commit therefore checks whether the key is present before removing
the entry, which also corrects the return value of keySet().removeAll()
in such cases.

Closes gh-37737

Signed-off-by: Swapnil kachare <swapnilkachare03@gmail.com>
(cherry picked from commit 9d3ca11)
sbrannen added a commit that referenced this pull request Nov 21, 2026
See gh-37737

(cherry picked from commit 92eb519)
@github-actions github-actions Bot added the status: backported An issue that has been backported to maintenance branches label Nov 21, 2026
@sbrannen sbrannen added this to the 7.1.1 milestone Nov 21, 2026
@sbrannen

Copy link
Copy Markdown
Member

Congratulations on submitting your first PR for the Spring Framework! 👍

This has been merged into main and backported to 7.0.x.

Thanks

@SwapnilKachare7

SwapnilKachare7 commented Nov 21, 2026 via email

Copy link
Copy Markdown
Contributor Author

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: backported An issue that has been backported to maintenance branches type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants