diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 196af8751..64fc5cfa9 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -45,7 +45,8 @@ The type attribute can be add,update,fix,remove. - + + Multiple calls of org.apache.commons.lang3.concurrent.LazyInitializer.initialize() are possible. StrBuilder#replaceAll ArrayIndexOutOfBoundsException BooleanUtils javadoc issues StringUtils#getLevenshteinDistance reduce memory consumption diff --git a/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java b/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java index be5482a80..a0f903c78 100644 --- a/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java +++ b/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java @@ -79,7 +79,10 @@ package org.apache.commons.lang3.concurrent; */ public abstract class LazyInitializer implements ConcurrentInitializer { /** Stores the managed object. */ - private volatile T object; + + private static final Object NoInit = new Object(); + + private volatile T object = (T) NoInit; /** * Returns the object wrapped by this instance. On first access the object @@ -95,10 +98,10 @@ public abstract class LazyInitializer implements ConcurrentInitializer { // volatile field T result = object; - if (result == null) { + if (result == NoInit) { synchronized (this) { result = object; - if (result == null) { + if (result == NoInit) { object = result = initialize(); } }