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 47e5b6aa1 RATIS-1919 Fix some sonar code smell and bugs in 
ratis-client/common/grpc (#951)
47e5b6aa1 is described below

commit 47e5b6aa148cfe777fb3b7742154fe6b417ea42a
Author: Potato <[email protected]>
AuthorDate: Fri Oct 27 23:47:44 2023 +0800

    RATIS-1919 Fix some sonar code smell and bugs in ratis-client/common/grpc 
(#951)
---
 .../src/main/java/org/apache/ratis/client/impl/BlockingImpl.java        | 1 +
 ratis-common/src/main/java/org/apache/ratis/protocol/RaftPeerId.java    | 2 ++
 ratis-common/src/main/java/org/apache/ratis/util/AutoCloseableLock.java | 1 +
 ratis-common/src/main/java/org/apache/ratis/util/AwaitToRun.java        | 2 +-
 .../main/java/org/apache/ratis/grpc/util/StreamObserverWithTimeout.java | 1 +
 5 files changed, 6 insertions(+), 1 deletion(-)

diff --git 
a/ratis-client/src/main/java/org/apache/ratis/client/impl/BlockingImpl.java 
b/ratis-client/src/main/java/org/apache/ratis/client/impl/BlockingImpl.java
index 742ee2901..4be9fa327 100644
--- a/ratis-client/src/main/java/org/apache/ratis/client/impl/BlockingImpl.java
+++ b/ratis-client/src/main/java/org/apache/ratis/client/impl/BlockingImpl.java
@@ -132,6 +132,7 @@ class BlockingImpl implements BlockingApi {
       try {
         sleepTime.sleep();
       } catch (InterruptedException e) {
+        Thread.currentThread().interrupt();
         throw new InterruptedIOException("retry policy=" + retryPolicy);
       }
     }
diff --git 
a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftPeerId.java 
b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftPeerId.java
index afb7ef357..7458d9339 100644
--- a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftPeerId.java
+++ b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftPeerId.java
@@ -17,6 +17,7 @@
  */
 package org.apache.ratis.protocol;
 
+import javax.annotation.concurrent.Immutable;
 import org.apache.ratis.proto.RaftProtos.RaftPeerIdProto;
 import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
 import org.apache.ratis.util.JavaUtils;
@@ -33,6 +34,7 @@ import java.util.function.Supplier;
  * <p>
  * This is a value-based class.
  */
+@Immutable
 public final class RaftPeerId {
   private static final Map<ByteString, RaftPeerId> BYTE_STRING_MAP = new 
ConcurrentHashMap<>();
   private static final Map<String, RaftPeerId> STRING_MAP = new 
ConcurrentHashMap<>();
diff --git 
a/ratis-common/src/main/java/org/apache/ratis/util/AutoCloseableLock.java 
b/ratis-common/src/main/java/org/apache/ratis/util/AutoCloseableLock.java
index 9fc6953c5..8a5409baf 100644
--- a/ratis-common/src/main/java/org/apache/ratis/util/AutoCloseableLock.java
+++ b/ratis-common/src/main/java/org/apache/ratis/util/AutoCloseableLock.java
@@ -39,6 +39,7 @@ public final class AutoCloseableLock implements AutoCloseable 
{
     return acquire(lock, null);
   }
 
+  @SuppressWarnings("java:S2222") // Locks should be release by calling {@link 
#close()}
   public static AutoCloseableLock acquire(final Lock lock, Runnable preUnlock) 
{
     lock.lock();
     return new AutoCloseableLock(lock, preUnlock);
diff --git a/ratis-common/src/main/java/org/apache/ratis/util/AwaitToRun.java 
b/ratis-common/src/main/java/org/apache/ratis/util/AwaitToRun.java
index 7eedef915..0222c1dc1 100644
--- a/ratis-common/src/main/java/org/apache/ratis/util/AwaitToRun.java
+++ b/ratis-common/src/main/java/org/apache/ratis/util/AwaitToRun.java
@@ -42,7 +42,7 @@ public class AwaitToRun implements AutoCloseable {
 
     @Override
     public void run() {
-      for (; ; ) {
+      while(!Thread.currentThread().isInterrupted()) {
         try {
           awaitForSignal.await();
         } catch (InterruptedException e) {
diff --git 
a/ratis-grpc/src/main/java/org/apache/ratis/grpc/util/StreamObserverWithTimeout.java
 
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/util/StreamObserverWithTimeout.java
index 723a5dd99..ff89e7d4b 100644
--- 
a/ratis-grpc/src/main/java/org/apache/ratis/grpc/util/StreamObserverWithTimeout.java
+++ 
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/util/StreamObserverWithTimeout.java
@@ -84,6 +84,7 @@ public final class StreamObserverWithTimeout<T> implements 
StreamObserver<T> {
       try {
         acquired = semaphore.tryAcquire(timeout.getDuration(), 
timeout.getUnit());
       } catch (InterruptedException e) {
+        Thread.currentThread().interrupt();
         throw new IllegalStateException("Interrupted onNext " + request, e);
       }
     }

Reply via email to