Commit 2a9b094
committed
Fix potential race condition in Lazy.getNullable()
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.1 parent 44f0f31 commit 2a9b094
1 file changed
+3
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
| 136 | + | |
| 137 | + | |
137 | 138 | | |
138 | 139 | | |
139 | | - | |
| 140 | + | |
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
| |||
0 commit comments