diff --git a/src/main/java/org/springframework/data/util/Lazy.java b/src/main/java/org/springframework/data/util/Lazy.java index 75dda3485..2edcd8784 100644 --- a/src/main/java/org/springframework/data/util/Lazy.java +++ b/src/main/java/org/springframework/data/util/Lazy.java @@ -34,6 +34,7 @@ import org.springframework.util.Assert; * * @author Oliver Gierke * @author Mark Paluch + * @author Henning Rohlfs * @since 2.0 */ @RequiredArgsConstructor @@ -45,7 +46,7 @@ public class Lazy implements Supplier { private final Supplier supplier; private @Nullable T value = null; - private boolean resolved = false; + private volatile boolean resolved = false; /** * Creates a new {@link Lazy} to produce an object lazily. @@ -203,15 +204,11 @@ public class Lazy implements Supplier { @Nullable public T getNullable() { - T value = this.value; - - if (this.resolved) { + if (resolved) { return value; } - value = supplier.get(); - - this.value = value; + this.value = supplier.get(); this.resolved = true; return value;