Clarify ConcurrentReferenceHashMap reference semantics - #37357
Open
rene-schakmann wants to merge 1 commit into
Open
rene-schakmann wants to merge 1 commit into
rene-schakmann wants to merge 1 commit into
Conversation
Prior to this commit, the Javadoc for ConcurrentReferenceHashMap stated that soft or weak references are used for both keys and values. However, the references are applied to the internal map entries, each of which holds strong references to its key and value. Consequently, an entry may be discarded even if its key and value are still strongly reachable from elsewhere, which differs from the semantics of WeakHashMap. This commit revises the class-level Javadoc as well as the Javadoc for the ReferenceType constants to document this behavior. Closes spring-projectsgh-24253 Signed-off-by: rene.schakmann <rene.schakmann@reetgroup.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
This PR addresses #24253 as a documentation change, as suggested by @philwebb and @sbrannen in the issue.
The Javadoc of
ConcurrentReferenceHashMapstated that it uses soft or weak references "for both keys and values". The soft or weak references (SoftEntryReference/WeakEntryReference) actually wrap the internalEntryobjects, and eachEntryholds strong references to its key and value. As a result, an entry may be discarded even if its key and value are still strongly reachable from elsewhere. ForWEAKthis typically happens on the next GC. This differs fromWeakHashMap, which is what the issue reporter ran into.Changes:
ReferenceTypeconstants now state that the references are used for map entries.No behavior change.
🤖 Generated with Claude Code