Browse Source

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 <jbj338033@gmail.com>
Closes #3368
labs/stable-value
jbj338033 3 months ago committed by Mark Paluch
parent
commit
ae291097d1
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 5
      src/main/java/org/springframework/data/util/Lazy.java

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

@ -133,10 +133,11 @@ public class Lazy<T> implements Supplier<T> { @@ -133,10 +133,11 @@ public class Lazy<T> implements Supplier<T> {
return value;
}
this.value = supplier.get();
T result = supplier.get();
this.value = result;
this.resolved = true;
return value;
return result;
}
/**

Loading…
Cancel
Save