From b9198fa7cd2bad1c3da13887544a018feca87636 Mon Sep 17 00:00:00 2001 From: Yiyang Zhou Date: Fri, 7 Nov 2025 18:35:56 +0800 Subject: [PATCH 1/5] RATIS-2352. Update spotbugs version to 4.8.6 and fix warnings --- pom.xml | 4 +- .../dev-support/findbugsExcludeFile.xml | 38 ++++++++ ratis-client/pom.xml | 11 +++ .../ratis/client/retry/ClientRetryEvent.java | 2 +- .../dev-support/findbugsExcludeFile.xml | 50 +++++++++++ ratis-common/pom.xml | 11 +++ .../ratis/conf/ReconfigurationBase.java | 2 +- .../ratis/conf/ReconfigurationStatus.java | 3 +- .../impl/DataStreamReplyByteBuffer.java | 5 +- .../impl/DataStreamRequestByteBuffer.java | 3 +- .../DataStreamRequestFilePositionCount.java | 3 +- .../ratis/protocol/DataStreamReplyHeader.java | 2 +- .../apache/ratis/protocol/GroupInfoReply.java | 4 +- .../ratis/protocol/RaftClientReply.java | 8 +- .../ratis/protocol/RaftClientRequest.java | 4 +- .../org/apache/ratis/protocol/RaftPeerId.java | 2 +- .../protocol/SetConfigurationRequest.java | 23 ++--- .../exceptions/LeaderNotReadyException.java | 2 +- .../exceptions/NotLeaderException.java | 5 +- .../exceptions/NotReplicatedException.java | 5 +- .../java/org/apache/ratis/util/JavaUtils.java | 51 +++++++++++ .../org/apache/ratis/util/SlidingWindow.java | 2 +- .../org/apache/ratis/util/TimeDuration.java | 2 +- .../dev-support/findbugsExcludeFile.xml | 26 ++++++ ratis-examples/pom.xml | 7 ++ .../dev-support/findbugsExcludeFile.xml | 26 ++++++ ratis-grpc/pom.xml | 11 +++ .../dev-support/findbugsExcludeFile.xml | 22 +++++ ratis-metrics-api/pom.xml | 11 +++ .../dev-support/findbugsExcludeFile.xml | 22 +++++ ratis-metrics-default/pom.xml | 11 +++ .../dev-support/findbugsExcludeFile.xml | 22 +++++ ratis-metrics-dropwizard3/pom.xml | 11 +++ .../dev-support/findbugsExcludeFile.xml | 38 ++++++++ ratis-netty/pom.xml | 12 +++ .../dev-support/findbugsExcludeFile.xml | 34 +++++++ ratis-server-api/pom.xml | 11 +++ .../dev-support/findbugsExcludeFile.xml | 90 +++++++++++++++++++ ratis-server/pom.xml | 11 +++ .../dev-support/findbugsExcludeFile.xml | 30 +++++++ ratis-shell/pom.xml | 7 ++ 41 files changed, 607 insertions(+), 37 deletions(-) create mode 100644 ratis-client/dev-support/findbugsExcludeFile.xml create mode 100644 ratis-common/dev-support/findbugsExcludeFile.xml create mode 100644 ratis-examples/dev-support/findbugsExcludeFile.xml create mode 100644 ratis-grpc/dev-support/findbugsExcludeFile.xml create mode 100644 ratis-metrics-api/dev-support/findbugsExcludeFile.xml create mode 100644 ratis-metrics-default/dev-support/findbugsExcludeFile.xml create mode 100644 ratis-metrics-dropwizard3/dev-support/findbugsExcludeFile.xml create mode 100644 ratis-netty/dev-support/findbugsExcludeFile.xml create mode 100644 ratis-server-api/dev-support/findbugsExcludeFile.xml create mode 100644 ratis-server/dev-support/findbugsExcludeFile.xml create mode 100644 ratis-shell/dev-support/findbugsExcludeFile.xml diff --git a/pom.xml b/pom.xml index 72cd5a646e..98bbd637e3 100644 --- a/pom.xml +++ b/pom.xml @@ -189,8 +189,8 @@ 0.6.1 2.8.0 - 4.2.1 - 4.2.0 + 4.8.6 + 4.8.6.2 apache.snapshots.https Apache Development Snapshot Repository diff --git a/ratis-client/dev-support/findbugsExcludeFile.xml b/ratis-client/dev-support/findbugsExcludeFile.xml new file mode 100644 index 0000000000..ef97b465fc --- /dev/null +++ b/ratis-client/dev-support/findbugsExcludeFile.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ratis-client/pom.xml b/ratis-client/pom.xml index 89cd67e7e6..26b2034983 100644 --- a/ratis-client/pom.xml +++ b/ratis-client/pom.xml @@ -59,4 +59,15 @@ test + + + + com.github.spotbugs + spotbugs-maven-plugin + + ${basedir}/dev-support/findbugsExcludeFile.xml + + + + diff --git a/ratis-client/src/main/java/org/apache/ratis/client/retry/ClientRetryEvent.java b/ratis-client/src/main/java/org/apache/ratis/client/retry/ClientRetryEvent.java index c6a8beb06f..5d5b2a9d57 100644 --- a/ratis-client/src/main/java/org/apache/ratis/client/retry/ClientRetryEvent.java +++ b/ratis-client/src/main/java/org/apache/ratis/client/retry/ClientRetryEvent.java @@ -56,7 +56,7 @@ public RaftClientRequest getRequest() { @Override public Throwable getCause() { - return cause; + return JavaUtils.snapshot(cause); } boolean isRequestTimeout(TimeDuration timeout) { diff --git a/ratis-common/dev-support/findbugsExcludeFile.xml b/ratis-common/dev-support/findbugsExcludeFile.xml new file mode 100644 index 0000000000..a8173d341b --- /dev/null +++ b/ratis-common/dev-support/findbugsExcludeFile.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ratis-common/pom.xml b/ratis-common/pom.xml index f60cc0240a..f6bc0ee413 100644 --- a/ratis-common/pom.xml +++ b/ratis-common/pom.xml @@ -59,4 +59,15 @@ test + + + + com.github.spotbugs + spotbugs-maven-plugin + + ${basedir}/dev-support/findbugsExcludeFile.xml + + + + diff --git a/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationBase.java b/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationBase.java index 8123e24141..3d8932a8c9 100644 --- a/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationBase.java +++ b/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationBase.java @@ -122,7 +122,7 @@ protected ReconfigurationBase(String name, RaftProperties properties) { @Override public RaftProperties getProperties() { - return properties; + return new RaftProperties(properties); } /** @return the new {@link RaftProperties} to be reconfigured to. */ diff --git a/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationStatus.java b/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationStatus.java index c584fe068a..cfea175118 100644 --- a/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationStatus.java +++ b/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationStatus.java @@ -18,6 +18,7 @@ package org.apache.ratis.conf; +import java.util.Collections; import java.util.Map; import java.util.Objects; @@ -138,7 +139,7 @@ public Timestamp getEndTime() { * otherwise, return null. */ public Map getChanges() { - return changes; + return Collections.unmodifiableMap(changes); } /** diff --git a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamReplyByteBuffer.java b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamReplyByteBuffer.java index 5cb5569be5..d6494b982a 100644 --- a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamReplyByteBuffer.java +++ b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamReplyByteBuffer.java @@ -23,6 +23,7 @@ import org.apache.ratis.protocol.DataStreamReply; import org.apache.ratis.protocol.DataStreamReplyHeader; import org.apache.ratis.proto.RaftProtos.DataStreamPacketHeaderProto.Type; +import org.apache.ratis.thirdparty.com.google.common.collect.ImmutableList; import java.nio.ByteBuffer; import java.util.Collection; @@ -83,7 +84,7 @@ public Builder setBytesWritten(long bytesWritten) { } public Builder setCommitInfos(Collection commitInfos) { - this.commitInfos = commitInfos; + this.commitInfos = ImmutableList.copyOf(commitInfos); return this; } @@ -137,7 +138,7 @@ public long getBytesWritten() { @Override public Collection getCommitInfos() { - return commitInfos; + return Collections.unmodifiableCollection(commitInfos); } @Override diff --git a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestByteBuffer.java b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestByteBuffer.java index 938ed793b4..0931222bcf 100644 --- a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestByteBuffer.java +++ b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestByteBuffer.java @@ -23,6 +23,7 @@ import org.apache.ratis.util.Preconditions; import java.nio.ByteBuffer; +import java.util.Collections; import java.util.List; /** @@ -41,6 +42,6 @@ public DataStreamRequestByteBuffer(DataStreamRequestHeader header, ByteBuffer bu @Override public List getWriteOptionList() { - return options; + return Collections.unmodifiableList(options); } } diff --git a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestFilePositionCount.java b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestFilePositionCount.java index ceb84ff6e0..a86452abe0 100644 --- a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestFilePositionCount.java +++ b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestFilePositionCount.java @@ -22,6 +22,7 @@ import org.apache.ratis.protocol.DataStreamRequest; import org.apache.ratis.protocol.DataStreamRequestHeader; +import java.util.Collections; import java.util.List; /** @@ -51,6 +52,6 @@ public FilePositionCount getFile() { @Override public List getWriteOptionList() { - return options; + return Collections.unmodifiableList(options); } } diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/DataStreamReplyHeader.java b/ratis-common/src/main/java/org/apache/ratis/protocol/DataStreamReplyHeader.java index 502b42672d..24d530e038 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/DataStreamReplyHeader.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/DataStreamReplyHeader.java @@ -51,6 +51,6 @@ public boolean isSuccess() { @Override public Collection getCommitInfos() { - return commitInfos; + return Collections.unmodifiableCollection(commitInfos); } } \ No newline at end of file diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/GroupInfoReply.java b/ratis-common/src/main/java/org/apache/ratis/protocol/GroupInfoReply.java index bfac81a2b0..08ff6494e2 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/GroupInfoReply.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/GroupInfoReply.java @@ -62,7 +62,7 @@ public RaftGroup getGroup() { } public RoleInfoProto getRoleInfoProto() { - return roleInfoProto; + return roleInfoProto == null ? null : roleInfoProto.toBuilder().build(); } public boolean isRaftStorageHealthy() { @@ -74,6 +74,6 @@ public Optional getConf() { } public LogInfoProto getLogInfoProto() { - return logInfoProto; + return logInfoProto == null ? null : logInfoProto.toBuilder().build(); } } diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientReply.java b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientReply.java index 64d667955d..673290f951 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientReply.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientReply.java @@ -92,7 +92,7 @@ public Builder setSuccess() { } public Builder setException(RaftException exception) { - this.exception = exception; + this.exception = JavaUtils.copyRaftException(exception); return this; } @@ -107,7 +107,7 @@ public Builder setLogIndex(long logIndex) { } public Builder setCommitInfos(Collection commitInfos) { - this.commitInfos = commitInfos; + this.commitInfos = JavaUtils.defensiveCopyOf(commitInfos); return this; } @@ -184,7 +184,7 @@ public static Builder newBuilder() { * @return the commit information if it is available; otherwise, return null. */ public Collection getCommitInfos() { - return commitInfos; + return Collections.unmodifiableCollection(commitInfos); } @Override @@ -258,6 +258,6 @@ public ReadIndexException getReadIndexException() { /** @return the exception, if there is any; otherwise, return null. */ public RaftException getException() { - return exception; + return JavaUtils.copyRaftException(exception); } } diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientRequest.java b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientRequest.java index ed41f1ea2c..79cc462d3a 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientRequest.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientRequest.java @@ -353,7 +353,7 @@ public Builder setType(Type type) { } public Builder setSlidingWindowEntry(SlidingWindowEntry slidingWindowEntry) { - this.slidingWindowEntry = slidingWindowEntry; + this.slidingWindowEntry = (slidingWindowEntry == null) ? null : slidingWindowEntry.toBuilder().build(); return this; } @@ -445,7 +445,7 @@ public Iterable getRepliedCallIds() { } public SlidingWindowEntry getSlidingWindowEntry() { - return slidingWindowEntry; + return slidingWindowEntry == null ? null : slidingWindowEntry.toBuilder().build(); } public Message getMessage() { 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 8db842d734..9077c67926 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 @@ -86,7 +86,7 @@ public RaftPeerIdProto getRaftPeerIdProto() { * @return id in {@link ByteString}. */ public ByteString toByteString() { - return id; + return id == null ? null : ByteString.copyFrom(id.toByteArray()); } @Override diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/SetConfigurationRequest.java b/ratis-common/src/main/java/org/apache/ratis/protocol/SetConfigurationRequest.java index 8234b4c432..67f8250418 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/SetConfigurationRequest.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/SetConfigurationRequest.java @@ -18,6 +18,7 @@ package org.apache.ratis.protocol; import org.apache.ratis.proto.RaftProtos; +import org.apache.ratis.util.JavaUtils; import org.apache.ratis.util.Preconditions; import java.util.Arrays; @@ -64,23 +65,23 @@ private Arguments(List serversInNewConf, List listenersInNew public List getPeersInNewConf(RaftProtos.RaftPeerRole role) { switch (role) { - case FOLLOWER: return serversInNewConf; - case LISTENER: return listenersInNewConf; + case FOLLOWER: return JavaUtils.unmodifiableListView(serversInNewConf); + case LISTENER: return JavaUtils.unmodifiableListView(listenersInNewConf); default: throw new IllegalArgumentException("Unexpected role " + role); } } public List getListenersInCurrentConf() { - return listenersInCurrentConf; + return JavaUtils.unmodifiableListView(listenersInCurrentConf); } public List getServersInCurrentConf() { - return serversInCurrentConf; + return JavaUtils.unmodifiableListView(serversInCurrentConf); } public List getServersInNewConf() { - return serversInNewConf; + return JavaUtils.unmodifiableListView(serversInNewConf); } public Mode getMode() { @@ -106,32 +107,32 @@ public static class Builder { private Mode mode = Mode.SET_UNCONDITIONALLY; public Builder setServersInNewConf(List serversInNewConf) { - this.serversInNewConf = serversInNewConf; + this.serversInNewConf = JavaUtils.defensiveCopyList(serversInNewConf); return this; } public Builder setListenersInNewConf(List listenersInNewConf) { - this.listenersInNewConf = listenersInNewConf; + this.listenersInNewConf = JavaUtils.defensiveCopyList(listenersInNewConf); return this; } public Builder setServersInNewConf(RaftPeer[] serversInNewConfArray) { - this.serversInNewConf = Arrays.asList(serversInNewConfArray); + this.serversInNewConf = JavaUtils.defensiveCopyList(Arrays.asList(serversInNewConfArray)); return this; } public Builder setListenersInNewConf(RaftPeer[] listenersInNewConfArray) { - this.listenersInNewConf = Arrays.asList(listenersInNewConfArray); + this.listenersInNewConf = JavaUtils.defensiveCopyList(Arrays.asList(listenersInNewConfArray)); return this; } public Builder setServersInCurrentConf(List serversInCurrentConf) { - this.serversInCurrentConf = serversInCurrentConf; + this.serversInCurrentConf = JavaUtils.defensiveCopyList(serversInCurrentConf); return this; } public Builder setListenersInCurrentConf(List listenersInCurrentConf) { - this.listenersInCurrentConf = listenersInCurrentConf; + this.listenersInCurrentConf = JavaUtils.defensiveCopyList(listenersInCurrentConf); return this; } diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/LeaderNotReadyException.java b/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/LeaderNotReadyException.java index fca3c5a78a..dd817ac12e 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/LeaderNotReadyException.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/LeaderNotReadyException.java @@ -40,6 +40,6 @@ public RaftGroupMemberId getServerId() { } public RaftGroupMemberIdProto getRaftGroupMemberIdProto() { - return serverId; + return serverId == null ? null : serverId.toBuilder().build(); } } diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotLeaderException.java b/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotLeaderException.java index c7dc6a3961..36bd8b202d 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotLeaderException.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotLeaderException.java @@ -19,6 +19,7 @@ import org.apache.ratis.protocol.RaftGroupMemberId; import org.apache.ratis.protocol.RaftPeer; +import org.apache.ratis.util.JavaUtils; import org.apache.ratis.util.Preconditions; import java.util.Collection; @@ -33,7 +34,7 @@ public NotLeaderException(RaftGroupMemberId memberId, RaftPeer suggestedLeader, super("Server " + memberId + " is not the leader" + (suggestedLeader != null ? ", suggested leader is: " + suggestedLeader : "")); this.suggestedLeader = suggestedLeader; - this.peers = peers != null? Collections.unmodifiableCollection(peers): Collections.emptyList(); + this.peers = JavaUtils.defensiveCopyOf(peers); Preconditions.assertUnique(this.peers); } @@ -42,6 +43,6 @@ public RaftPeer getSuggestedLeader() { } public Collection getPeers() { - return peers; + return Collections.unmodifiableCollection(peers); } } diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotReplicatedException.java b/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotReplicatedException.java index 37ff816245..747d64b7cc 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotReplicatedException.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotReplicatedException.java @@ -19,6 +19,7 @@ import org.apache.ratis.proto.RaftProtos.CommitInfoProto; import org.apache.ratis.proto.RaftProtos.ReplicationLevel; +import org.apache.ratis.util.JavaUtils; import java.util.Collection; @@ -40,7 +41,7 @@ public NotReplicatedException(long callId, ReplicationLevel requiredReplication, public NotReplicatedException(long callId, ReplicationLevel requiredReplication, long logIndex, Collection commitInfos) { this(callId, requiredReplication, logIndex); - this.commitInfos = commitInfos; + this.commitInfos = JavaUtils.defensiveCopyOf(commitInfos); } public long getCallId() { @@ -56,6 +57,6 @@ public long getLogIndex() { } public Collection getCommitInfos() { - return commitInfos; + return JavaUtils.defensiveCopyOf(commitInfos); } } diff --git a/ratis-common/src/main/java/org/apache/ratis/util/JavaUtils.java b/ratis-common/src/main/java/org/apache/ratis/util/JavaUtils.java index 958e88cee5..8ad1d5441f 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/JavaUtils.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/JavaUtils.java @@ -17,6 +17,7 @@ */ package org.apache.ratis.util; +import org.apache.ratis.protocol.exceptions.RaftException; import org.apache.ratis.util.function.CheckedFunction; import org.apache.ratis.util.function.CheckedRunnable; import org.apache.ratis.util.function.CheckedSupplier; @@ -29,8 +30,11 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Date; +import java.util.List; import java.util.Objects; import java.util.Timer; import java.util.TimerTask; @@ -318,4 +322,51 @@ static OUTPUT supplyAndWrapAsCompletionExc throw new CompletionException(t); } } + + static Collection defensiveCopyOf(Collection src) { + if (src == null || src.isEmpty()) { + return Collections.emptyList(); + } + return Collections.unmodifiableList(new ArrayList<>(src)); + } + + static List defensiveCopyList(List src) { + if (src == null || src.isEmpty()) { + return Collections.emptyList(); + } + return Collections.unmodifiableList(new ArrayList<>(src)); + } + + static List unmodifiableListView(List src) { + if (src == null || src.isEmpty()) { + return Collections.emptyList(); + } + return Collections.unmodifiableList(src); + } + + static Throwable snapshot(Throwable e) { + if (e == null) { + return null; + } + final Throwable copy = (e instanceof Exception) + ? new Exception(e.getMessage(), e.getCause()) + : new Throwable(e.getMessage(), e.getCause()); + copy.setStackTrace(e.getStackTrace().clone()); + for (Throwable s : e.getSuppressed()) { + copy.addSuppressed(s); + } + return copy; + } + + static RaftException copyRaftException(RaftException e) { + if (e == null) { + return null; + } + RaftException c = new RaftException(e.getMessage(), e.getCause()); + c.setStackTrace(e.getStackTrace().clone()); + for (Throwable s : e.getSuppressed()) { + c.addSuppressed(s); + } + return c; + } } diff --git a/ratis-common/src/main/java/org/apache/ratis/util/SlidingWindow.java b/ratis-common/src/main/java/org/apache/ratis/util/SlidingWindow.java index 7e37d81322..9dc92c5094 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/SlidingWindow.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/SlidingWindow.java @@ -385,7 +385,7 @@ public synchronized void resetFirstSeqNum() { /** Fail all requests starting from the given seqNum. */ public synchronized void fail(final long startingSeqNum, Throwable e) { - exception = e; + exception = JavaUtils.snapshot(e); boolean handled = false; for(long i = startingSeqNum; i <= requests.lastSeqNum(); i++) { diff --git a/ratis-common/src/main/java/org/apache/ratis/util/TimeDuration.java b/ratis-common/src/main/java/org/apache/ratis/util/TimeDuration.java index 2a520083e0..a80ef66080 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/TimeDuration.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/TimeDuration.java @@ -122,7 +122,7 @@ String getDefault() { /** @return the entire abbreviation list for this unit. */ public List getSymbols() { - return symbols; + return JavaUtils.unmodifiableListView(symbols); } /** @return the corresponding {@link Abbreviation}. */ diff --git a/ratis-examples/dev-support/findbugsExcludeFile.xml b/ratis-examples/dev-support/findbugsExcludeFile.xml new file mode 100644 index 0000000000..26260f03ea --- /dev/null +++ b/ratis-examples/dev-support/findbugsExcludeFile.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ratis-examples/pom.xml b/ratis-examples/pom.xml index 8464f93c03..c52019334f 100644 --- a/ratis-examples/pom.xml +++ b/ratis-examples/pom.xml @@ -179,6 +179,13 @@ + + com.github.spotbugs + spotbugs-maven-plugin + + ${basedir}/dev-support/findbugsExcludeFile.xml + + diff --git a/ratis-grpc/dev-support/findbugsExcludeFile.xml b/ratis-grpc/dev-support/findbugsExcludeFile.xml new file mode 100644 index 0000000000..c13c34ade0 --- /dev/null +++ b/ratis-grpc/dev-support/findbugsExcludeFile.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ratis-grpc/pom.xml b/ratis-grpc/pom.xml index ba3110178d..360131d55b 100644 --- a/ratis-grpc/pom.xml +++ b/ratis-grpc/pom.xml @@ -74,4 +74,15 @@ test + + + + com.github.spotbugs + spotbugs-maven-plugin + + ${basedir}/dev-support/findbugsExcludeFile.xml + + + + diff --git a/ratis-metrics-api/dev-support/findbugsExcludeFile.xml b/ratis-metrics-api/dev-support/findbugsExcludeFile.xml new file mode 100644 index 0000000000..2b3c140b14 --- /dev/null +++ b/ratis-metrics-api/dev-support/findbugsExcludeFile.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/ratis-metrics-api/pom.xml b/ratis-metrics-api/pom.xml index 16c368084a..db368269e2 100644 --- a/ratis-metrics-api/pom.xml +++ b/ratis-metrics-api/pom.xml @@ -51,4 +51,15 @@ test + + + + com.github.spotbugs + spotbugs-maven-plugin + + ${basedir}/dev-support/findbugsExcludeFile.xml + + + + diff --git a/ratis-metrics-default/dev-support/findbugsExcludeFile.xml b/ratis-metrics-default/dev-support/findbugsExcludeFile.xml new file mode 100644 index 0000000000..3b4b52c664 --- /dev/null +++ b/ratis-metrics-default/dev-support/findbugsExcludeFile.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/ratis-metrics-default/pom.xml b/ratis-metrics-default/pom.xml index ada045e961..b561cbe924 100644 --- a/ratis-metrics-default/pom.xml +++ b/ratis-metrics-default/pom.xml @@ -56,4 +56,15 @@ test + + + + com.github.spotbugs + spotbugs-maven-plugin + + ${basedir}/dev-support/findbugsExcludeFile.xml + + + + diff --git a/ratis-metrics-dropwizard3/dev-support/findbugsExcludeFile.xml b/ratis-metrics-dropwizard3/dev-support/findbugsExcludeFile.xml new file mode 100644 index 0000000000..c413237ff8 --- /dev/null +++ b/ratis-metrics-dropwizard3/dev-support/findbugsExcludeFile.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/ratis-metrics-dropwizard3/pom.xml b/ratis-metrics-dropwizard3/pom.xml index f50ee14a30..3d06f57cc5 100644 --- a/ratis-metrics-dropwizard3/pom.xml +++ b/ratis-metrics-dropwizard3/pom.xml @@ -94,4 +94,15 @@ + + + + com.github.spotbugs + spotbugs-maven-plugin + + ${basedir}/dev-support/findbugsExcludeFile.xml + + + + diff --git a/ratis-netty/dev-support/findbugsExcludeFile.xml b/ratis-netty/dev-support/findbugsExcludeFile.xml new file mode 100644 index 0000000000..0e1646df77 --- /dev/null +++ b/ratis-netty/dev-support/findbugsExcludeFile.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ratis-netty/pom.xml b/ratis-netty/pom.xml index f9d34fffc5..5688a1fa4a 100644 --- a/ratis-netty/pom.xml +++ b/ratis-netty/pom.xml @@ -90,4 +90,16 @@ + + + + + com.github.spotbugs + spotbugs-maven-plugin + + ${basedir}/dev-support/findbugsExcludeFile.xml + + + + diff --git a/ratis-server-api/dev-support/findbugsExcludeFile.xml b/ratis-server-api/dev-support/findbugsExcludeFile.xml new file mode 100644 index 0000000000..33c6d02a47 --- /dev/null +++ b/ratis-server-api/dev-support/findbugsExcludeFile.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ratis-server-api/pom.xml b/ratis-server-api/pom.xml index 0dfb3cc1d1..feed49190c 100644 --- a/ratis-server-api/pom.xml +++ b/ratis-server-api/pom.xml @@ -64,4 +64,15 @@ test + + + + com.github.spotbugs + spotbugs-maven-plugin + + ${basedir}/dev-support/findbugsExcludeFile.xml + + + + diff --git a/ratis-server/dev-support/findbugsExcludeFile.xml b/ratis-server/dev-support/findbugsExcludeFile.xml new file mode 100644 index 0000000000..9180856202 --- /dev/null +++ b/ratis-server/dev-support/findbugsExcludeFile.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ratis-server/pom.xml b/ratis-server/pom.xml index f700ac6c5d..2c0bc93a25 100644 --- a/ratis-server/pom.xml +++ b/ratis-server/pom.xml @@ -94,4 +94,15 @@ test + + + + com.github.spotbugs + spotbugs-maven-plugin + + ${basedir}/dev-support/findbugsExcludeFile.xml + + + + diff --git a/ratis-shell/dev-support/findbugsExcludeFile.xml b/ratis-shell/dev-support/findbugsExcludeFile.xml new file mode 100644 index 0000000000..c29ededa06 --- /dev/null +++ b/ratis-shell/dev-support/findbugsExcludeFile.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ratis-shell/pom.xml b/ratis-shell/pom.xml index 32361a46c3..efa96a7866 100644 --- a/ratis-shell/pom.xml +++ b/ratis-shell/pom.xml @@ -85,6 +85,13 @@ + + com.github.spotbugs + spotbugs-maven-plugin + + ${basedir}/dev-support/findbugsExcludeFile.xml + + From 429c6b0b4268ed7b456103e5ca80b24bb10e50ed Mon Sep 17 00:00:00 2001 From: Symious Date: Fri, 7 Nov 2025 22:54:14 +0800 Subject: [PATCH 2/5] RATIS-2352. Revert all code changes --- .../ratis/client/retry/ClientRetryEvent.java | 2 +- .../ratis/conf/ReconfigurationBase.java | 2 +- .../ratis/conf/ReconfigurationStatus.java | 3 +- .../impl/DataStreamReplyByteBuffer.java | 5 +- .../impl/DataStreamRequestByteBuffer.java | 3 +- .../DataStreamRequestFilePositionCount.java | 3 +- .../ratis/protocol/DataStreamReplyHeader.java | 2 +- .../apache/ratis/protocol/GroupInfoReply.java | 4 +- .../ratis/protocol/RaftClientReply.java | 8 +-- .../ratis/protocol/RaftClientRequest.java | 4 +- .../org/apache/ratis/protocol/RaftPeerId.java | 2 +- .../protocol/SetConfigurationRequest.java | 23 ++++----- .../exceptions/LeaderNotReadyException.java | 2 +- .../exceptions/NotLeaderException.java | 5 +- .../exceptions/NotReplicatedException.java | 5 +- .../java/org/apache/ratis/util/JavaUtils.java | 51 ------------------- .../org/apache/ratis/util/SlidingWindow.java | 2 +- .../org/apache/ratis/util/TimeDuration.java | 2 +- 18 files changed, 35 insertions(+), 93 deletions(-) diff --git a/ratis-client/src/main/java/org/apache/ratis/client/retry/ClientRetryEvent.java b/ratis-client/src/main/java/org/apache/ratis/client/retry/ClientRetryEvent.java index 5d5b2a9d57..c6a8beb06f 100644 --- a/ratis-client/src/main/java/org/apache/ratis/client/retry/ClientRetryEvent.java +++ b/ratis-client/src/main/java/org/apache/ratis/client/retry/ClientRetryEvent.java @@ -56,7 +56,7 @@ public RaftClientRequest getRequest() { @Override public Throwable getCause() { - return JavaUtils.snapshot(cause); + return cause; } boolean isRequestTimeout(TimeDuration timeout) { diff --git a/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationBase.java b/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationBase.java index 3d8932a8c9..8123e24141 100644 --- a/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationBase.java +++ b/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationBase.java @@ -122,7 +122,7 @@ protected ReconfigurationBase(String name, RaftProperties properties) { @Override public RaftProperties getProperties() { - return new RaftProperties(properties); + return properties; } /** @return the new {@link RaftProperties} to be reconfigured to. */ diff --git a/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationStatus.java b/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationStatus.java index cfea175118..c584fe068a 100644 --- a/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationStatus.java +++ b/ratis-common/src/main/java/org/apache/ratis/conf/ReconfigurationStatus.java @@ -18,7 +18,6 @@ package org.apache.ratis.conf; -import java.util.Collections; import java.util.Map; import java.util.Objects; @@ -139,7 +138,7 @@ public Timestamp getEndTime() { * otherwise, return null. */ public Map getChanges() { - return Collections.unmodifiableMap(changes); + return changes; } /** diff --git a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamReplyByteBuffer.java b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamReplyByteBuffer.java index d6494b982a..5cb5569be5 100644 --- a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamReplyByteBuffer.java +++ b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamReplyByteBuffer.java @@ -23,7 +23,6 @@ import org.apache.ratis.protocol.DataStreamReply; import org.apache.ratis.protocol.DataStreamReplyHeader; import org.apache.ratis.proto.RaftProtos.DataStreamPacketHeaderProto.Type; -import org.apache.ratis.thirdparty.com.google.common.collect.ImmutableList; import java.nio.ByteBuffer; import java.util.Collection; @@ -84,7 +83,7 @@ public Builder setBytesWritten(long bytesWritten) { } public Builder setCommitInfos(Collection commitInfos) { - this.commitInfos = ImmutableList.copyOf(commitInfos); + this.commitInfos = commitInfos; return this; } @@ -138,7 +137,7 @@ public long getBytesWritten() { @Override public Collection getCommitInfos() { - return Collections.unmodifiableCollection(commitInfos); + return commitInfos; } @Override diff --git a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestByteBuffer.java b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestByteBuffer.java index 0931222bcf..938ed793b4 100644 --- a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestByteBuffer.java +++ b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestByteBuffer.java @@ -23,7 +23,6 @@ import org.apache.ratis.util.Preconditions; import java.nio.ByteBuffer; -import java.util.Collections; import java.util.List; /** @@ -42,6 +41,6 @@ public DataStreamRequestByteBuffer(DataStreamRequestHeader header, ByteBuffer bu @Override public List getWriteOptionList() { - return Collections.unmodifiableList(options); + return options; } } diff --git a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestFilePositionCount.java b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestFilePositionCount.java index a86452abe0..ceb84ff6e0 100644 --- a/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestFilePositionCount.java +++ b/ratis-common/src/main/java/org/apache/ratis/datastream/impl/DataStreamRequestFilePositionCount.java @@ -22,7 +22,6 @@ import org.apache.ratis.protocol.DataStreamRequest; import org.apache.ratis.protocol.DataStreamRequestHeader; -import java.util.Collections; import java.util.List; /** @@ -52,6 +51,6 @@ public FilePositionCount getFile() { @Override public List getWriteOptionList() { - return Collections.unmodifiableList(options); + return options; } } diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/DataStreamReplyHeader.java b/ratis-common/src/main/java/org/apache/ratis/protocol/DataStreamReplyHeader.java index 24d530e038..502b42672d 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/DataStreamReplyHeader.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/DataStreamReplyHeader.java @@ -51,6 +51,6 @@ public boolean isSuccess() { @Override public Collection getCommitInfos() { - return Collections.unmodifiableCollection(commitInfos); + return commitInfos; } } \ No newline at end of file diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/GroupInfoReply.java b/ratis-common/src/main/java/org/apache/ratis/protocol/GroupInfoReply.java index 08ff6494e2..bfac81a2b0 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/GroupInfoReply.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/GroupInfoReply.java @@ -62,7 +62,7 @@ public RaftGroup getGroup() { } public RoleInfoProto getRoleInfoProto() { - return roleInfoProto == null ? null : roleInfoProto.toBuilder().build(); + return roleInfoProto; } public boolean isRaftStorageHealthy() { @@ -74,6 +74,6 @@ public Optional getConf() { } public LogInfoProto getLogInfoProto() { - return logInfoProto == null ? null : logInfoProto.toBuilder().build(); + return logInfoProto; } } diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientReply.java b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientReply.java index 673290f951..64d667955d 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientReply.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientReply.java @@ -92,7 +92,7 @@ public Builder setSuccess() { } public Builder setException(RaftException exception) { - this.exception = JavaUtils.copyRaftException(exception); + this.exception = exception; return this; } @@ -107,7 +107,7 @@ public Builder setLogIndex(long logIndex) { } public Builder setCommitInfos(Collection commitInfos) { - this.commitInfos = JavaUtils.defensiveCopyOf(commitInfos); + this.commitInfos = commitInfos; return this; } @@ -184,7 +184,7 @@ public static Builder newBuilder() { * @return the commit information if it is available; otherwise, return null. */ public Collection getCommitInfos() { - return Collections.unmodifiableCollection(commitInfos); + return commitInfos; } @Override @@ -258,6 +258,6 @@ public ReadIndexException getReadIndexException() { /** @return the exception, if there is any; otherwise, return null. */ public RaftException getException() { - return JavaUtils.copyRaftException(exception); + return exception; } } diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientRequest.java b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientRequest.java index 79cc462d3a..ed41f1ea2c 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientRequest.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientRequest.java @@ -353,7 +353,7 @@ public Builder setType(Type type) { } public Builder setSlidingWindowEntry(SlidingWindowEntry slidingWindowEntry) { - this.slidingWindowEntry = (slidingWindowEntry == null) ? null : slidingWindowEntry.toBuilder().build(); + this.slidingWindowEntry = slidingWindowEntry; return this; } @@ -445,7 +445,7 @@ public Iterable getRepliedCallIds() { } public SlidingWindowEntry getSlidingWindowEntry() { - return slidingWindowEntry == null ? null : slidingWindowEntry.toBuilder().build(); + return slidingWindowEntry; } public Message getMessage() { 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 9077c67926..8db842d734 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 @@ -86,7 +86,7 @@ public RaftPeerIdProto getRaftPeerIdProto() { * @return id in {@link ByteString}. */ public ByteString toByteString() { - return id == null ? null : ByteString.copyFrom(id.toByteArray()); + return id; } @Override diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/SetConfigurationRequest.java b/ratis-common/src/main/java/org/apache/ratis/protocol/SetConfigurationRequest.java index 67f8250418..8234b4c432 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/SetConfigurationRequest.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/SetConfigurationRequest.java @@ -18,7 +18,6 @@ package org.apache.ratis.protocol; import org.apache.ratis.proto.RaftProtos; -import org.apache.ratis.util.JavaUtils; import org.apache.ratis.util.Preconditions; import java.util.Arrays; @@ -65,23 +64,23 @@ private Arguments(List serversInNewConf, List listenersInNew public List getPeersInNewConf(RaftProtos.RaftPeerRole role) { switch (role) { - case FOLLOWER: return JavaUtils.unmodifiableListView(serversInNewConf); - case LISTENER: return JavaUtils.unmodifiableListView(listenersInNewConf); + case FOLLOWER: return serversInNewConf; + case LISTENER: return listenersInNewConf; default: throw new IllegalArgumentException("Unexpected role " + role); } } public List getListenersInCurrentConf() { - return JavaUtils.unmodifiableListView(listenersInCurrentConf); + return listenersInCurrentConf; } public List getServersInCurrentConf() { - return JavaUtils.unmodifiableListView(serversInCurrentConf); + return serversInCurrentConf; } public List getServersInNewConf() { - return JavaUtils.unmodifiableListView(serversInNewConf); + return serversInNewConf; } public Mode getMode() { @@ -107,32 +106,32 @@ public static class Builder { private Mode mode = Mode.SET_UNCONDITIONALLY; public Builder setServersInNewConf(List serversInNewConf) { - this.serversInNewConf = JavaUtils.defensiveCopyList(serversInNewConf); + this.serversInNewConf = serversInNewConf; return this; } public Builder setListenersInNewConf(List listenersInNewConf) { - this.listenersInNewConf = JavaUtils.defensiveCopyList(listenersInNewConf); + this.listenersInNewConf = listenersInNewConf; return this; } public Builder setServersInNewConf(RaftPeer[] serversInNewConfArray) { - this.serversInNewConf = JavaUtils.defensiveCopyList(Arrays.asList(serversInNewConfArray)); + this.serversInNewConf = Arrays.asList(serversInNewConfArray); return this; } public Builder setListenersInNewConf(RaftPeer[] listenersInNewConfArray) { - this.listenersInNewConf = JavaUtils.defensiveCopyList(Arrays.asList(listenersInNewConfArray)); + this.listenersInNewConf = Arrays.asList(listenersInNewConfArray); return this; } public Builder setServersInCurrentConf(List serversInCurrentConf) { - this.serversInCurrentConf = JavaUtils.defensiveCopyList(serversInCurrentConf); + this.serversInCurrentConf = serversInCurrentConf; return this; } public Builder setListenersInCurrentConf(List listenersInCurrentConf) { - this.listenersInCurrentConf = JavaUtils.defensiveCopyList(listenersInCurrentConf); + this.listenersInCurrentConf = listenersInCurrentConf; return this; } diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/LeaderNotReadyException.java b/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/LeaderNotReadyException.java index dd817ac12e..fca3c5a78a 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/LeaderNotReadyException.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/LeaderNotReadyException.java @@ -40,6 +40,6 @@ public RaftGroupMemberId getServerId() { } public RaftGroupMemberIdProto getRaftGroupMemberIdProto() { - return serverId == null ? null : serverId.toBuilder().build(); + return serverId; } } diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotLeaderException.java b/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotLeaderException.java index 36bd8b202d..c7dc6a3961 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotLeaderException.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotLeaderException.java @@ -19,7 +19,6 @@ import org.apache.ratis.protocol.RaftGroupMemberId; import org.apache.ratis.protocol.RaftPeer; -import org.apache.ratis.util.JavaUtils; import org.apache.ratis.util.Preconditions; import java.util.Collection; @@ -34,7 +33,7 @@ public NotLeaderException(RaftGroupMemberId memberId, RaftPeer suggestedLeader, super("Server " + memberId + " is not the leader" + (suggestedLeader != null ? ", suggested leader is: " + suggestedLeader : "")); this.suggestedLeader = suggestedLeader; - this.peers = JavaUtils.defensiveCopyOf(peers); + this.peers = peers != null? Collections.unmodifiableCollection(peers): Collections.emptyList(); Preconditions.assertUnique(this.peers); } @@ -43,6 +42,6 @@ public RaftPeer getSuggestedLeader() { } public Collection getPeers() { - return Collections.unmodifiableCollection(peers); + return peers; } } diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotReplicatedException.java b/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotReplicatedException.java index 747d64b7cc..37ff816245 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotReplicatedException.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/exceptions/NotReplicatedException.java @@ -19,7 +19,6 @@ import org.apache.ratis.proto.RaftProtos.CommitInfoProto; import org.apache.ratis.proto.RaftProtos.ReplicationLevel; -import org.apache.ratis.util.JavaUtils; import java.util.Collection; @@ -41,7 +40,7 @@ public NotReplicatedException(long callId, ReplicationLevel requiredReplication, public NotReplicatedException(long callId, ReplicationLevel requiredReplication, long logIndex, Collection commitInfos) { this(callId, requiredReplication, logIndex); - this.commitInfos = JavaUtils.defensiveCopyOf(commitInfos); + this.commitInfos = commitInfos; } public long getCallId() { @@ -57,6 +56,6 @@ public long getLogIndex() { } public Collection getCommitInfos() { - return JavaUtils.defensiveCopyOf(commitInfos); + return commitInfos; } } diff --git a/ratis-common/src/main/java/org/apache/ratis/util/JavaUtils.java b/ratis-common/src/main/java/org/apache/ratis/util/JavaUtils.java index 8ad1d5441f..958e88cee5 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/JavaUtils.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/JavaUtils.java @@ -17,7 +17,6 @@ */ package org.apache.ratis.util; -import org.apache.ratis.protocol.exceptions.RaftException; import org.apache.ratis.util.function.CheckedFunction; import org.apache.ratis.util.function.CheckedRunnable; import org.apache.ratis.util.function.CheckedSupplier; @@ -30,11 +29,8 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.text.SimpleDateFormat; -import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.Date; -import java.util.List; import java.util.Objects; import java.util.Timer; import java.util.TimerTask; @@ -322,51 +318,4 @@ static OUTPUT supplyAndWrapAsCompletionExc throw new CompletionException(t); } } - - static Collection defensiveCopyOf(Collection src) { - if (src == null || src.isEmpty()) { - return Collections.emptyList(); - } - return Collections.unmodifiableList(new ArrayList<>(src)); - } - - static List defensiveCopyList(List src) { - if (src == null || src.isEmpty()) { - return Collections.emptyList(); - } - return Collections.unmodifiableList(new ArrayList<>(src)); - } - - static List unmodifiableListView(List src) { - if (src == null || src.isEmpty()) { - return Collections.emptyList(); - } - return Collections.unmodifiableList(src); - } - - static Throwable snapshot(Throwable e) { - if (e == null) { - return null; - } - final Throwable copy = (e instanceof Exception) - ? new Exception(e.getMessage(), e.getCause()) - : new Throwable(e.getMessage(), e.getCause()); - copy.setStackTrace(e.getStackTrace().clone()); - for (Throwable s : e.getSuppressed()) { - copy.addSuppressed(s); - } - return copy; - } - - static RaftException copyRaftException(RaftException e) { - if (e == null) { - return null; - } - RaftException c = new RaftException(e.getMessage(), e.getCause()); - c.setStackTrace(e.getStackTrace().clone()); - for (Throwable s : e.getSuppressed()) { - c.addSuppressed(s); - } - return c; - } } diff --git a/ratis-common/src/main/java/org/apache/ratis/util/SlidingWindow.java b/ratis-common/src/main/java/org/apache/ratis/util/SlidingWindow.java index 9dc92c5094..7e37d81322 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/SlidingWindow.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/SlidingWindow.java @@ -385,7 +385,7 @@ public synchronized void resetFirstSeqNum() { /** Fail all requests starting from the given seqNum. */ public synchronized void fail(final long startingSeqNum, Throwable e) { - exception = JavaUtils.snapshot(e); + exception = e; boolean handled = false; for(long i = startingSeqNum; i <= requests.lastSeqNum(); i++) { diff --git a/ratis-common/src/main/java/org/apache/ratis/util/TimeDuration.java b/ratis-common/src/main/java/org/apache/ratis/util/TimeDuration.java index a80ef66080..2a520083e0 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/TimeDuration.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/TimeDuration.java @@ -122,7 +122,7 @@ String getDefault() { /** @return the entire abbreviation list for this unit. */ public List getSymbols() { - return JavaUtils.unmodifiableListView(symbols); + return symbols; } /** @return the corresponding {@link Abbreviation}. */ From 6f8961dc3e337724fb0875892fd5de755f73c70b Mon Sep 17 00:00:00 2001 From: Symious Date: Fri, 7 Nov 2025 23:07:28 +0800 Subject: [PATCH 3/5] RATIS-2352. Fix all by add to xml --- .../dev-support/findbugsExcludeFile.xml | 14 ++- .../dev-support/findbugsExcludeFile.xml | 96 +++++++++++++++++-- 2 files changed, 97 insertions(+), 13 deletions(-) diff --git a/ratis-client/dev-support/findbugsExcludeFile.xml b/ratis-client/dev-support/findbugsExcludeFile.xml index ef97b465fc..3a808c4486 100644 --- a/ratis-client/dev-support/findbugsExcludeFile.xml +++ b/ratis-client/dev-support/findbugsExcludeFile.xml @@ -16,23 +16,27 @@ --> - + - + - + - + - + + + + + \ No newline at end of file diff --git a/ratis-common/dev-support/findbugsExcludeFile.xml b/ratis-common/dev-support/findbugsExcludeFile.xml index a8173d341b..3148752344 100644 --- a/ratis-common/dev-support/findbugsExcludeFile.xml +++ b/ratis-common/dev-support/findbugsExcludeFile.xml @@ -16,35 +16,115 @@ --> - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 505df03736aab65bf41c20a77e87d632d2ded311 Mon Sep 17 00:00:00 2001 From: Yiyang Zhou Date: Thu, 13 Nov 2025 14:40:59 +0800 Subject: [PATCH 4/5] RATIS-2352. Update spotbugs version to 4.9.7 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 98bbd637e3..06fe55dffe 100644 --- a/pom.xml +++ b/pom.xml @@ -189,8 +189,8 @@ 0.6.1 2.8.0 - 4.8.6 - 4.8.6.2 + 4.9.7 + 4.9.7.0 apache.snapshots.https Apache Development Snapshot Repository From 9b653238bd34fa8b1f2fca22c3b949951ccf3aa5 Mon Sep 17 00:00:00 2001 From: Yiyang Zhou Date: Thu, 13 Nov 2025 15:13:27 +0800 Subject: [PATCH 5/5] Revert "RATIS-2352. Update spotbugs version to 4.9.7" This reverts commit 505df03736aab65bf41c20a77e87d632d2ded311. --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 06fe55dffe..98bbd637e3 100644 --- a/pom.xml +++ b/pom.xml @@ -189,8 +189,8 @@ 0.6.1 2.8.0 - 4.9.7 - 4.9.7.0 + 4.8.6 + 4.8.6.2 apache.snapshots.https Apache Development Snapshot Repository