diff --git a/src/main/java/org/springframework/data/util/Lazy.java b/src/main/java/org/springframework/data/util/Lazy.java index 8385a13bb..8b474170b 100644 --- a/src/main/java/org/springframework/data/util/Lazy.java +++ b/src/main/java/org/springframework/data/util/Lazy.java @@ -30,6 +30,7 @@ import org.springframework.util.ObjectUtils; * * @author Oliver Gierke * @author Mark Paluch + * @author Henning Rohlfs * @since 2.0 */ public class Lazy implements Supplier { @@ -39,7 +40,7 @@ public class Lazy implements Supplier { private final Supplier supplier; private @Nullable T value; - private boolean resolved; + private volatile boolean resolved; /** * Creates a new {@link Lazy} instance for the given supplier. @@ -222,18 +223,14 @@ public class Lazy implements Supplier { @Nullable public T getNullable() { - T value = this.value; - if (this.resolved) { - return value; + return this.value; } - value = supplier.get(); - - this.value = value; + this.value = supplier.get(); this.resolved = true; - return value; + return this.value; } /*