Skip to content

Commit ae29109

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 44f0f31 commit ae29109

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
@@ -133,10 +133,11 @@ public T getNullable() {
133133
return value;
134134
}
135135

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

139-
return value;
140+
return result;
140141
}
141142

142143
/**

0 commit comments

Comments
 (0)