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

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new e26213a71 RATIS-2336. PeerProxyMap.getProxy() could return null. 
(#1290)
e26213a71 is described below

commit e26213a711b317b1c63e64b9ac62dd2db8ee0e48
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Wed Sep 24 09:38:15 2025 -0700

    RATIS-2336. PeerProxyMap.getProxy() could return null. (#1290)
---
 ratis-common/src/main/java/org/apache/ratis/util/PeerProxyMap.java | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/ratis-common/src/main/java/org/apache/ratis/util/PeerProxyMap.java 
b/ratis-common/src/main/java/org/apache/ratis/util/PeerProxyMap.java
index eda41a009..868b65cc3 100644
--- a/ratis-common/src/main/java/org/apache/ratis/util/PeerProxyMap.java
+++ b/ratis-common/src/main/java/org/apache/ratis/util/PeerProxyMap.java
@@ -59,7 +59,10 @@ public class PeerProxyMap<PROXY extends Closeable> 
implements RaftPeer.Add, Clos
     }
 
     PROXY getProxy() throws IOException {
-      if (proxy == null) {
+      final PROXY p = proxy;
+      if (p != null) {
+        return p;
+      } else {
         synchronized (this) {
           if (proxy == null) {
             final LifeCycle.State current = lifeCycle.getCurrentState();
@@ -69,9 +72,9 @@ public class PeerProxyMap<PROXY extends Closeable> implements 
RaftPeer.Add, Clos
             lifeCycle.startAndTransition(
                 () -> proxy = createProxyImpl(peer), IOException.class);
           }
+          return Objects.requireNonNull(proxy, "proxy");
         }
       }
-      return proxy;
     }
 
     Optional<PROXY> setNullProxyAndClose() {

Reply via email to