Skip to content

Conversation

jbj338033
Copy link

The getNullable() method had a subtle race condition where the value field could be read as null after being assigned but before the resolved flag was set to true. This could occur if another thread read the value between lines 136 and 137.

By using a local variable to store the supplier's result and returning that directly, we ensure that the thread that computes the value will always return the correct result, regardless of what other threads observe.

This change maintains the existing behavior documented in the class Javadoc that the supplier may be called multiple times under concurrent access, while fixing the potential for incorrect null returns.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 22, 2025
The getNullable() method had a subtle race condition where the value field
could be read as null after being assigned but before the resolved flag was
set to true. This could occur if another thread read the value between lines
136 and 137.

By using a local variable to store the supplier's result and returning that
directly, we ensure that the thread that computes the value will always
return the correct result, regardless of what other threads observe.

This change maintains the existing behavior documented in the class Javadoc
that the supplier may be called multiple times under concurrent access, while
fixing the potential for incorrect null returns.

Signed-off-by: jbj338033 <[email protected]>
@jbj338033 jbj338033 force-pushed the fix/lazy-race-condition branch from 2a9b094 to ffe1946 Compare September 22, 2025 11:50
@mp911de mp911de self-assigned this Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants