Merge "Suppress warnings with suggested coding patterns."
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java
index c9b39fe..0821082 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/Action.java
@@ -97,7 +97,7 @@
     return "?";
   }
 
-  private List<OwnerInfo> getOwners(OwnersDb db, Collection<String> files) {
+  private static List<OwnerInfo> getOwners(OwnersDb db, Collection<String> files) {
     Map<String, OwnerWeights> weights = new HashMap<>();
     db.findOwners(files, weights, new ArrayList<>());
     List<OwnerInfo> result = new ArrayList<>();
@@ -176,7 +176,7 @@
     Collection<String> changedFiles = changeData.currentFilePaths();
     Map<String, Set<String>> file2Owners = db.findOwners(changedFiles);
 
-    Boolean addDebugMsg = (params.debug != null) ? params.debug : config.getAddDebugMsg();
+    boolean addDebugMsg = (params.debug != null) ? params.debug : config.getAddDebugMsg();
     RestResult obj = new RestResult(config, projectState, changeData, addDebugMsg);
     obj.patchset = patchset;
     obj.ownerRevision = db.revision;
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnerWeights.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnerWeights.java
index 233f1d2..9437fc0 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnerWeights.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnerWeights.java
@@ -38,7 +38,7 @@
  */
 class OwnerWeights {
   static class WeightComparator implements Comparator<String> {
-    private Map<String, OwnerWeights> map;
+    private final Map<String, OwnerWeights> map;
 
     WeightComparator(Map<String, OwnerWeights> weights) {
       map = weights;
@@ -79,8 +79,7 @@
   void addFile(String path, int level) {
     // If a file is added multiple times,
     // it should be added with lowest level first.
-    if (!files.contains(path)) {
-      files.add(path);
+    if (files.add(path)) {
       if (level <= 1) {
         countL1++;
       } else if (level <= 2) {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java
index 34e9c1e..14869df 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/OwnersDb.java
@@ -372,7 +372,7 @@
           Set<String> patterns = dir2Globs.get(dirPath + "/");
           for (String pat : patterns) {
             PathMatcher matcher = fileSystem.getPathMatcher("glob:" + pat);
-            if (matcher.matches(Paths.get(dirPath + "/" + baseName))) {
+            if (matcher.matches(Paths.get(dirPath, baseName))) {
               foundStar |= findStarOwner(pat, distance, paths, distances);
               foundNoParentGlob |= noParentGlobs.contains(pat);
               // Do not break here, a file could match multiple globs
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/Parser.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/Parser.java
index c1cd591..c13213c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/Parser.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/Parser.java
@@ -104,12 +104,12 @@
   // A parser keeps current permissionBackend, readFiles, repoManager, project, branch,
   // included file path, and debug/trace logs.
   private final PermissionBackend permissionBackend;
-  private Map<String, String> readFiles;
-  private GitRepositoryManager repoManager;
-  private String branch; // All owners files are read from the same branch.
-  private IncludeStack stack; // a stack of including files.
-  private List<String> logs; // Keeps debug/trace messages.
-  private Map<String, Result> savedResults; // projectName:filePath => Parser.Result
+  private final Map<String, String> readFiles;
+  private final GitRepositoryManager repoManager;
+  private final String branch; // All owners files are read from the same branch.
+  private final IncludeStack stack; // a stack of including files.
+  private final List<String> logs; // Keeps debug/trace messages.
+  private final Map<String, Result> savedResults; // projectName:filePath => Parser.Result
 
   static class IncludeStack {
     Deque<String> projectName; // project/repository name of included file
diff --git a/src/test/java/com/googlesource/gerrit/plugins/findowners/IncludeIT.java b/src/test/java/com/googlesource/gerrit/plugins/findowners/IncludeIT.java
index 192fbf6..55cf6fb 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/findowners/IncludeIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/IncludeIT.java
@@ -29,15 +29,15 @@
   private static final FluentLogger logger = FluentLogger.forEnclosingClass();
   @Rule public Watcher watcher = new Watcher(logger);
 
-  private String getRepoFileLog(String msg1, String msg2) {
+  private static String getRepoFileLog(String msg1, String msg2) {
     return "getRepoFile:" + msg1 + ", getFile:" + msg2 + ", ";
   }
 
-  private String concat(String s1, String s2) {
+  private static String concat(String s1, String s2) {
     return s1 + s2;
   }
 
-  private String concat(String s1, String s2, String s3) {
+  private static String concat(String s1, String s2, String s3) {
     return s1 + s2 + s3;
   }
 
diff --git a/src/test/java/com/googlesource/gerrit/plugins/findowners/ParserTest.java b/src/test/java/com/googlesource/gerrit/plugins/findowners/ParserTest.java
index 8a0481b..a458249 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/findowners/ParserTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/findowners/ParserTest.java
@@ -245,7 +245,7 @@
     }
   }
 
-  private void testOneIncludeOrFileLine(
+  private static void testOneIncludeOrFileLine(
       String project, String line, String keyword, String projectName, String filePath) {
     String[] results = Parser.parseInclude(project, line);
     assertThat(results).hasLength(3);
@@ -254,11 +254,12 @@
     assertThat(results[2]).isEqualTo(filePath);
   }
 
-  private void testOneFileLine(String project, String line, String projectName, String filePath) {
+  private static void testOneFileLine(
+      String project, String line, String projectName, String filePath) {
     testOneIncludeOrFileLine(project, line, "file", projectName, filePath);
   }
 
-  private void testOneIncludeLine(
+  private static void testOneIncludeLine(
       String project, String line, String projectName, String filePath) {
     testOneIncludeOrFileLine(project, line, "include", projectName, filePath);
   }