Repository navigation
Fix stale ConcurrentReferenceHashMap size after compute - #37577
Merged
sbrannen merged 1 commit intoOct 25, 2026
Merged
Conversation
ConcurrentReferenceHashMap size after compute
Prior to this commit, when compute(), computeIfPresent() or merge() removed an entry because the function returned null, the reference to the entry was released, but the segment count was only updated once a subsequent operation purged released references. As a consequence, size() and isEmpty() still accounted for the removed entry; for example, isEmpty() returned false right after removing the only entry. remove(Object) and remove(Object, Object) restructure the segment after releasing a reference. This commit applies the same restructuring to compute(), computeIfPresent() and merge(). See spring-projectsgh-35794 Closes spring-projectsgh-37577 Signed-off-by: Jialin Chen <cccll2019@gmail.com>
sbrannen
force-pushed
the
fix/crhm-size-after-compute-removal
branch
from
October 25, 2026 16:11
cb0b6cd to
3a88326
Compare
Contributor
|
Fixed via cb0da83 |
Member
|
Hi @CCCLL, Congratulations on making your first contribution to the Spring Framework! 👍🏻 This has been merged into Thanks |
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.
When
compute(),computeIfPresent()ormerge()removes an entryfrom a
ConcurrentReferenceHashMapbecause the function returnsnull,size()andisEmpty()still account for that entry until a lateroperation happens to purge released references.
These methods release the reference to the removed entry, but unlike
remove(Object)andremove(Object, Object), their tasks do not useTaskOption.RESTRUCTURE_AFTER, so the segment count is not updatedright away. This change adds
RESTRUCTURE_AFTERto the tasks ofcompute(),computeIfPresent()andmerge().This is a regression from the dedicated implementations introduced in
gh-35794: with 6.2.12, the default
ConcurrentMapimplementationsremoved entries through
remove(Object, Object), so the map was emptyright away; 6.2.13 and 7.0.x report a size of 1.
The
compute(),computeIfPresent()andmerge()tests now assertthat the map is empty right after the removal. These assertions fail
without the change and pass with it.
./gradlew :spring-core:checkpasses on JDK 25.