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 14eb0bf05 RATIS-2002. Fix findbugs warnings in LogSegmentPath (#1017)
14eb0bf05 is described below
commit 14eb0bf057c89954a05e7d5c9915f71074591d47
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Thu Jan 18 02:27:33 2024 +0100
RATIS-2002. Fix findbugs warnings in LogSegmentPath (#1017)
---
.../server/raftlog/segmented/LogSegmentPath.java | 23 ++++++++++------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git
a/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/LogSegmentPath.java
b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/LogSegmentPath.java
index e1de7a543..45dc9a335 100644
---
a/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/LogSegmentPath.java
+++
b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/LogSegmentPath.java
@@ -17,7 +17,6 @@
*/
package org.apache.ratis.server.raftlog.segmented;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.ratis.server.storage.RaftStorage;
import org.apache.ratis.util.Preconditions;
import org.slf4j.Logger;
@@ -30,6 +29,7 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
+import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
@@ -38,9 +38,12 @@ import java.util.regex.Matcher;
*
* This is a value-based class.
*/
-public final class LogSegmentPath implements Comparable<LogSegmentPath> {
+public final class LogSegmentPath {
static final Logger LOG = LoggerFactory.getLogger(LogSegmentPath.class);
+ private static final Comparator<LogSegmentPath> COMPARATOR =
+ Comparator.comparing(LogSegmentPath::getStartEnd);
+
private final Path path;
private final LogSegmentStartEnd startEnd;
@@ -57,12 +60,6 @@ public final class LogSegmentPath implements
Comparable<LogSegmentPath> {
return startEnd;
}
- @Override
- @SuppressFBWarnings("EQ_COMPARETO_USE_OBJECT_EQUALS")
- public int compareTo(LogSegmentPath that) {
- return Comparator.comparing(LogSegmentPath::getStartEnd).compare(this,
that);
- }
-
@Override
public String toString() {
return path+ "(" + startEnd + ")";
@@ -84,7 +81,7 @@ public final class LogSegmentPath implements
Comparable<LogSegmentPath> {
Optional.ofNullable(matchLogSegment(path)).ifPresent(list::add);
}
}
- list.sort(Comparator.naturalOrder());
+ list.sort(COMPARATOR);
return list;
}
@@ -100,9 +97,9 @@ public final class LogSegmentPath implements
Comparable<LogSegmentPath> {
return Optional.ofNullable(matchCloseSegment(path)).orElseGet(() ->
matchOpenSegment(path));
}
- @SuppressFBWarnings("NP_NULL_ON_SOME_PATH")
private static LogSegmentPath matchCloseSegment(Path path) {
- final Matcher matcher =
LogSegmentStartEnd.getClosedSegmentPattern().matcher(path.getFileName().toString());
+ final String fileName =
String.valueOf(Objects.requireNonNull(path).getFileName());
+ final Matcher matcher =
LogSegmentStartEnd.getClosedSegmentPattern().matcher(fileName);
if (matcher.matches()) {
Preconditions.assertTrue(matcher.groupCount() == 2);
return newInstance(path, matcher.group(1), matcher.group(2));
@@ -110,9 +107,9 @@ public final class LogSegmentPath implements
Comparable<LogSegmentPath> {
return null;
}
- @SuppressFBWarnings("NP_NULL_ON_SOME_PATH")
private static LogSegmentPath matchOpenSegment(Path path) {
- final Matcher matcher =
LogSegmentStartEnd.getOpenSegmentPattern().matcher(path.getFileName().toString());
+ final String fileName =
String.valueOf(Objects.requireNonNull(path).getFileName());
+ final Matcher matcher =
LogSegmentStartEnd.getOpenSegmentPattern().matcher(fileName);
if (matcher.matches()) {
if (path.toFile().length() > 0L) {
return newInstance(path, matcher.group(1), null);