This is an automated email from the ASF dual-hosted git repository.

mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/master by this push:
     new 03bfc41  Fix race condition
03bfc41 is described below

commit 03bfc414122444917257ef86687bf7e63cd7aa03
Author: Matt Sicker <[email protected]>
AuthorDate: Tue Jan 18 21:41:01 2022 -0600

    Fix race condition
    
    Signed-off-by: Matt Sicker <[email protected]>
---
 .../log4j/plugins/convert/TypeConverterRegistry.java      | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git 
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/convert/TypeConverterRegistry.java
 
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/convert/TypeConverterRegistry.java
index f3301ce..c2ecd8e 100644
--- 
a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/convert/TypeConverterRegistry.java
+++ 
b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/convert/TypeConverterRegistry.java
@@ -20,8 +20,10 @@ import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.plugins.di.model.PluginSource;
 import org.apache.logging.log4j.plugins.spi.Bean;
 import org.apache.logging.log4j.plugins.spi.BeanManager;
+import org.apache.logging.log4j.plugins.util.LazyValue;
 import org.apache.logging.log4j.plugins.util.PluginLoader;
 import org.apache.logging.log4j.plugins.util.TypeUtil;
+import org.apache.logging.log4j.plugins.util.Value;
 import org.apache.logging.log4j.status.StatusLogger;
 import org.apache.logging.log4j.util.LoaderUtil;
 
@@ -45,7 +47,7 @@ public class TypeConverterRegistry {
 
     private static final Logger LOGGER = StatusLogger.getLogger();
     private static final String DEFAULT_CONVERTERS_PACKAGE = 
"org.apache.logging.log4j.core.config.plugins.convert";
-    private static volatile TypeConverterRegistry INSTANCE;
+    private static final Value<TypeConverterRegistry> INSTANCE = 
LazyValue.forSupplier(TypeConverterRegistry::new);
     private static final Object INSTANCE_LOCK = new Object();
 
     private final ConcurrentMap<Type, TypeConverter<?>> registry = new 
ConcurrentHashMap<>();
@@ -56,16 +58,7 @@ public class TypeConverterRegistry {
      * @return the singleton instance.
      */
     public static TypeConverterRegistry getInstance() {
-        TypeConverterRegistry result = INSTANCE;
-        if (result == null) {
-            synchronized (INSTANCE_LOCK) {
-                result = INSTANCE;
-                if (result == null) {
-                    INSTANCE = result = new TypeConverterRegistry();
-                }
-            }
-        }
-        return result;
+        return INSTANCE.get();
     }
 
     /**

Reply via email to