Repository navigation
Fix case-insensitive remove in LinkedCaseInsensitiveMap views - #37607
Open
guanchengang wants to merge 1 commit into
Open
guanchengang wants to merge 1 commit into
guanchengang wants to merge 1 commit into
Conversation
`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>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
KeySet.remove(Object)reported false when the mapped value was null, because it relied onLinkedCaseInsensitiveMap.remove(Object)returning a non-null previous value. CheckcontainsKey(Object)first and delegate the removal to the map.KeySet.removeAll(Collection)andEntrySet.removeAll(Collection)fell back toAbstractSet.removeAll, which delegates toCollection.containson the argument when its size is not larger than this set. That check is case-sensitive and also relies onMap.Entry.equals, so keys such as "Key" and "KEY" were not matched and nothing was removed.Delegate to the view's ownremove(Object)for every element instead, which is case-insensitive and already handles null values and non-matching element types.