Skip to content

Commit

Permalink
RATIS-1919 Fix some sonar code smell and bugs in ratis-client/common/…
Browse files Browse the repository at this point in the history
…grpc (apache#951)
  • Loading branch information
OneSizeFitsQuorum authored Oct 27, 2023
1 parent 3e7f9e5 commit 47e5b6a
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public RaftClientRequest newRequestImpl() {
try {
sleepTime.sleep();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new InterruptedIOException("retry policy=" + retryPolicy);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +34,7 @@
* <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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static AutoCloseableLock acquire(final Lock lock) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private RunnableImpl(Runnable runMethod) {

@Override
public void run() {
for (; ; ) {
while(!Thread.currentThread().isInterrupted()) {
try {
awaitForSignal.await();
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private void acquire(StringSupplier request) {
try {
acquired = semaphore.tryAcquire(timeout.getDuration(), timeout.getUnit());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("Interrupted onNext " + request, e);
}
}
Expand Down

0 comments on commit 47e5b6a

Please sign in to comment.