Skip to content

Commit 0e4820e

Browse files
jbj338033mp911de
authored andcommitted
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. 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]> Closes #3368
1 parent ede202b commit 0e4820e

File tree

1 file changed

+3
-2
lines changed
  • src/main/java/org/springframework/data/util

1 file changed

+3
-2
lines changed

src/main/java/org/springframework/data/util/Lazy.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,11 @@ public T getNullable() {
132132
return value;
133133
}
134134

135-
this.value = supplier.get();
135+
T result = supplier.get();
136+
this.value = result;
136137
this.resolved = true;
137138

138-
return value;
139+
return result;
139140
}
140141

141142
/**

0 commit comments

Comments
 (0)