Skip to content

Clarify ConcurrentReferenceHashMap reference semantics - #37357

Open
rene-schakmann wants to merge 1 commit into
spring-projects:mainfrom
rene-schakmann:gh-24253
Open

rene-schakmann wants to merge 1 commit into
spring-projects:mainfrom
rene-schakmann:gh-24253

Conversation

@rene-schakmann

Copy link
Copy Markdown

This PR addresses #24253 as a documentation change, as suggested by @philwebb and @sbrannen in the issue.

The Javadoc of ConcurrentReferenceHashMap stated that it uses soft or weak references "for both keys and values". The soft or weak references (SoftEntryReference / WeakEntryReference) actually wrap the internal Entry objects, and each Entry holds 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. For WEAK this typically happens on the next GC. This differs from WeakHashMap, which is what the issue reporter ran into.

Changes:

  • Class-level Javadoc now says that references are applied to the map's entries, and gains a paragraph explaining the consequences: an entry's lifetime is not tied to its key's reachability, and the map is meant for caches whose entries can be recomputed rather than for associating data with a key for the key's lifetime.
  • The ReferenceType constants now state that the references are used for map entries.

No behavior change.

🤖 Generated with Claude Code

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>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 30, 2026
@sbrannen sbrannen added type: documentation A documentation task in: core Issues in core modules (aop, beans, core, context, expression) labels Oct 1, 2026
@sbrannen sbrannen self-assigned this Oct 1, 2026
@sbrannen sbrannen removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 1, 2026
@sbrannen sbrannen added this to the 7.1.0-RC1 milestone Oct 1, 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) type: documentation A documentation task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants