You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2022/11/18 03:49:47 UTC

[logging-log4j2] branch master updated: Use compareAndExchangeRelease with getAcquire

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 207e728fb2 Use compareAndExchangeRelease with getAcquire
207e728fb2 is described below

commit 207e728fb2cbc65dd67bfa3915eee5f45d178e39
Author: Matt Sicker <ma...@apache.org>
AuthorDate: Thu Nov 17 21:49:25 2022 -0600

    Use compareAndExchangeRelease with getAcquire
    
    Using compareAndSet with getAcquire sort of defeats the purpose of the fence as it uses volatile get which has stronger memory safety than getAcquire.
    
    Signed-off-by: Matt Sicker <ma...@apache.org>
---
 log4j-api/src/main/java/org/apache/logging/log4j/util/LazyUtil.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/LazyUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/LazyUtil.java
index 10991ca4ad..a75935ea8c 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/LazyUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/LazyUtil.java
@@ -138,7 +138,7 @@ final class LazyUtil {
                 return unwrapNull(currentValue);
             }
             final T newValue = supplier.get();
-            if (VALUE.compareAndSet(this, (Object) null, wrapNull(newValue))) {
+            if (VALUE.compareAndExchangeRelease(this, null, wrapNull(newValue)) == null) {
                 return newValue;
             }
             final Object value = VALUE.getAcquire(this);