Adapt to recent upstream tooling migrations

* Bazel 9.x requires java_library to be loaded explicitly from
  @rules_java//java:defs.bzl. Add the load where needed.

* protobuf upstream absorbed the proto rules into @protobuf//bazel:.
  Switch the proto_library load in proto/BUILD to
  @protobuf//bazel:proto_library.bzl.

* The @rules_java upgrade ships a newer errorprone that tightens
  the [CheckReturnValue] bug pattern. Address it by adding
  @CanIgnoreReturnValue to fluent-mutator methods whose callers
  legitimately discard the return value, and by binding the
  remaining site-local discards to `var unused`.

Change-Id: I875c4406f1b2333b45447b0e4ac57946b5dde44e
diff --git a/java/com/google/gerrit/plugins/codeowners/acceptance/AbstractCodeOwnersTest.java b/java/com/google/gerrit/plugins/codeowners/acceptance/AbstractCodeOwnersTest.java
index b377109..3d84823 100644
--- a/java/com/google/gerrit/plugins/codeowners/acceptance/AbstractCodeOwnersTest.java
+++ b/java/com/google/gerrit/plugins/codeowners/acceptance/AbstractCodeOwnersTest.java
@@ -240,7 +240,7 @@
     LabelDefinitionInput input = new LabelDefinitionInput();
     input.function = "NoOp";
     input.values = ImmutableMap.of("+1", "Override", " 0", "No Override");
-    gApi.projects().name(project.get()).label(labelName).create(input).get();
+    var unused = gApi.projects().name(project.get()).label(labelName).create(input).get();
 
     // Allow to vote on the Owners-Override label.
     projectOperations
diff --git a/java/com/google/gerrit/plugins/codeowners/acceptance/testsuite/TestCodeOwnerConfigCreation.java b/java/com/google/gerrit/plugins/codeowners/acceptance/testsuite/TestCodeOwnerConfigCreation.java
index e47e1cc..e43288e 100644
--- a/java/com/google/gerrit/plugins/codeowners/acceptance/testsuite/TestCodeOwnerConfigCreation.java
+++ b/java/com/google/gerrit/plugins/codeowners/acceptance/testsuite/TestCodeOwnerConfigCreation.java
@@ -19,6 +19,7 @@
 import com.google.auto.value.AutoValue;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
 import com.google.gerrit.acceptance.testsuite.ThrowingFunction;
 import com.google.gerrit.entities.BranchNameKey;
 import com.google.gerrit.entities.Project;
@@ -258,6 +259,7 @@
      * @param codeOwnerEmail email of the code owner
      * @return the Builder instance for chaining calls
      */
+    @CanIgnoreReturnValue
     public Builder addCodeOwnerEmail(String codeOwnerEmail) {
       return addCodeOwner(
           CodeOwnerReference.create(requireNonNull(codeOwnerEmail, "codeOwnerEmail")));
@@ -287,6 +289,7 @@
      * @param codeOwnerSet code owner set that should be added
      * @return the Builder instance for chaining calls
      */
+    @CanIgnoreReturnValue
     public Builder addCodeOwnerSet(CodeOwnerSet codeOwnerSet) {
       codeOwnerSetsBuilder().add(requireNonNull(codeOwnerSet, "codeOwnerSet"));
       return this;
@@ -305,6 +308,7 @@
      * @param codeOwnerConfigReference reference to the code owner config that should be imported
      * @return the Builder instance for chaining calls
      */
+    @CanIgnoreReturnValue
     public Builder addImport(CodeOwnerConfigReference codeOwnerConfigReference) {
       importsBuilder().add(requireNonNull(codeOwnerConfigReference, "codeOwnerConfigReference"));
       return this;
@@ -331,6 +335,7 @@
      *
      * @return the key of the code owner config
      */
+    @CanIgnoreReturnValue
     public CodeOwnerConfig.Key create() {
       TestCodeOwnerConfigCreation creation = autoBuild();
       return creation.codeOwnerConfigCreator().applyAndThrowSilently(creation);
diff --git a/java/com/google/gerrit/plugins/codeowners/api/ProjectCodeOwners.java b/java/com/google/gerrit/plugins/codeowners/api/ProjectCodeOwners.java
index 5f99cd1..76020bc 100644
--- a/java/com/google/gerrit/plugins/codeowners/api/ProjectCodeOwners.java
+++ b/java/com/google/gerrit/plugins/codeowners/api/ProjectCodeOwners.java
@@ -15,6 +15,7 @@
 package com.google.gerrit.plugins.codeowners.api;
 
 import com.google.common.collect.ImmutableList;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
 import com.google.gerrit.common.Nullable;
 import com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo;
 import com.google.gerrit.extensions.restapi.NotImplementedException;
@@ -37,6 +38,7 @@
    * @param input the input specifying which parameters should be updated
    * @return the update code owner project configuration
    */
+  @CanIgnoreReturnValue
   CodeOwnerProjectConfigInfo updateConfig(CodeOwnerProjectConfigInput input)
       throws RestApiException;
 
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfig.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfig.java
index b72ab39..0031cf2 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfig.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfig.java
@@ -20,6 +20,7 @@
 import com.google.auto.value.AutoValue;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
 import com.google.gerrit.common.Nullable;
 import com.google.gerrit.entities.BranchNameKey;
 import com.google.gerrit.entities.Project;
@@ -163,6 +164,7 @@
      * @param imports the imports of this code owner config
      * @return the Builder instance for chaining calls
      */
+    @CanIgnoreReturnValue
     public Builder setImports(ImmutableList<CodeOwnerConfigReference> imports) {
       return setImports(ImmutableSet.copyOf(imports));
     }
@@ -184,6 +186,7 @@
      * @param codeOwnerConfigReference reference to the code owner config that should be imported
      * @return the Builder instance for chaining calls
      */
+    @CanIgnoreReturnValue
     public Builder addImport(CodeOwnerConfigReference codeOwnerConfigReference) {
       importsBuilder().add(codeOwnerConfigReference);
       return this;
@@ -195,6 +198,7 @@
      *
      * @return the Builder instance for chaining calls
      */
+    @CanIgnoreReturnValue
     public Builder setIgnoreParentCodeOwners() {
       return setIgnoreParentCodeOwners(true);
     }
@@ -208,6 +212,7 @@
      * @param codeOwnerSets the code owner sets of this code owner config
      * @return the Builder instance for chaining calls
      */
+    @CanIgnoreReturnValue
     public Builder setCodeOwnerSets(ImmutableList<CodeOwnerSet> codeOwnerSets) {
       return setCodeOwnerSets(ImmutableSet.copyOf(codeOwnerSets));
     }
@@ -229,6 +234,7 @@
      * @param codeOwnerSet the code owner set
      * @return the Builder instance for chaining calls
      */
+    @CanIgnoreReturnValue
     public Builder addCodeOwnerSet(CodeOwnerSet codeOwnerSet) {
       codeOwnerSetsBuilder().add(requireNonNull(codeOwnerSet, "codeOwnerSet"));
       return this;
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigFile.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigFile.java
index c51f05f..801e93f 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigFile.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigFile.java
@@ -20,6 +20,7 @@
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Strings;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
 import com.google.gerrit.metrics.Timer0;
 import com.google.gerrit.metrics.Timer1;
 import com.google.gerrit.plugins.codeowners.metrics.CodeOwnerMetrics;
@@ -195,6 +196,7 @@
    *     should be applied
    * @return this {@code CodeOwnerConfigFile} instance to allow chaining calls
    */
+  @CanIgnoreReturnValue
   public CodeOwnerConfigFile setCodeOwnerConfigUpdate(CodeOwnerConfigUpdate codeOwnerConfigUpdate) {
     this.codeOwnerConfigUpdate = Optional.of(codeOwnerConfigUpdate);
     return this;
@@ -256,6 +258,7 @@
   }
 
   @Override
+  @CanIgnoreReturnValue
   public RevCommit commit(MetaDataUpdate update) throws IOException {
     // Reject the creation of a code owner config if the branch doesn't exist.
     checkState(
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigHierarchy.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigHierarchy.java
index 49c06bb..0eb87eb 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigHierarchy.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigHierarchy.java
@@ -289,7 +289,7 @@
               transientCodeOwnerConfigCache, metaCodeOwnerConfigKey, metaRevision, absolutePath);
       if (pathCodeOwners.isPresent()) {
         logger.atFine().log("visit code owner config %s", metaCodeOwnerConfigKey);
-        pathCodeOwnersVisitor.visit(pathCodeOwners.get());
+        var unused = pathCodeOwnersVisitor.visit(pathCodeOwners.get());
       } else {
         logger.atFine().log("code owner config %s not found", metaCodeOwnerConfigKey);
       }
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigReference.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigReference.java
index c9892e4..45a1c3d 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigReference.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigReference.java
@@ -19,6 +19,7 @@
 import static java.util.Objects.requireNonNull;
 
 import com.google.auto.value.AutoValue;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
 import com.google.gerrit.entities.Project;
 import com.google.gerrit.entities.RefNames;
 import java.nio.file.Path;
@@ -175,6 +176,7 @@
      *     prefix may be omitted
      * @return the Builder instance for chaining calls
      */
+    @CanIgnoreReturnValue
     public Builder setBranch(String branch) {
       requireNonNull(branch, "branch");
       return setBranch(Optional.of(RefNames.fullName(branch)));
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerResolver.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerResolver.java
index 38ce3e0..f8b027d 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerResolver.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerResolver.java
@@ -27,6 +27,7 @@
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Streams;
 import com.google.common.flogger.FluentLogger;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
 import com.google.gerrit.entities.Account;
 import com.google.gerrit.entities.Project;
 import com.google.gerrit.exceptions.StorageException;
@@ -152,6 +153,7 @@
    *     visible to the current user
    * @return the {@link CodeOwnerResolver} instance for chaining calls
    */
+  @CanIgnoreReturnValue
   public CodeOwnerResolver enforceVisibility(boolean enforceVisibility) {
     logger.atFine().log("enforceVisibility = %s", enforceVisibility);
     this.enforceVisibility = enforceVisibility;
@@ -174,6 +176,7 @@
    *     see the accounts of the code owners)
    * @return the {@link CodeOwnerResolver} instance for chaining calls
    */
+  @CanIgnoreReturnValue
   public CodeOwnerResolver forUser(IdentifiedUser user) {
     logger.atFine().log("user = %s", user.getLoggableName());
     this.user = user;
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerScoring.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerScoring.java
index ce89e07..1cc8d12 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerScoring.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerScoring.java
@@ -20,6 +20,7 @@
 import com.google.auto.value.AutoValue;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableListMultimap;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
 import java.util.Comparator;
 import java.util.Optional;
 
@@ -166,6 +167,7 @@
      * @param value the scoring value that should be put for the code owner
      * @return the Builder instance for chaining calls
      */
+    @CanIgnoreReturnValue
     public Builder putValueForCodeOwner(CodeOwner codeOwner, int value) {
       requireNonNull(codeOwner, "codeOwner");
       checkState(value >= 0, "value cannot be negative: %s", value);
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerSet.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerSet.java
index 43f49d5..f140ec2 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerSet.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerSet.java
@@ -21,6 +21,7 @@
 import com.google.auto.value.AutoValue;
 import com.google.common.collect.ImmutableMultimap;
 import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
 import java.util.Arrays;
 import java.util.Set;
 
@@ -165,6 +166,7 @@
      * @param codeOwnerConfigReferences references to the code owner configs that should be imported
      * @return the Builder instance for chaining calls
      */
+    @CanIgnoreReturnValue
     public abstract Builder setImports(
         ImmutableSet<CodeOwnerConfigReference> codeOwnerConfigReferences);
 
@@ -199,6 +201,7 @@
      * @param codeOwnerReference reference to the code owner
      * @return the Builder instance for chaining calls
      */
+    @CanIgnoreReturnValue
     public Builder addCodeOwner(CodeOwnerReference codeOwnerReference) {
       codeOwnersBuilder().add(requireNonNull(codeOwnerReference, "codeOwnerReference"));
       return this;
@@ -215,6 +218,7 @@
      * @param annotation annotation that should be added
      * @return the Builder instance for chaining calls
      */
+    @CanIgnoreReturnValue
     public Builder addAnnotation(String email, CodeOwnerAnnotation annotation) {
       return addAnnotations(CodeOwnerReference.create(email), ImmutableSet.of(annotation));
     }
@@ -227,6 +231,7 @@
      * @param annotations annotations that should be added
      * @return the Builder instance for chaining calls
      */
+    @CanIgnoreReturnValue
     public Builder addAnnotations(
         CodeOwnerReference codeOwnerReference, Set<CodeOwnerAnnotation> annotations) {
       requireNonNull(codeOwnerReference, "codeOwnerReference");
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersOnAddReviewer.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersOnAddReviewer.java
index 3ce8e01..2723a95 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersOnAddReviewer.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersOnAddReviewer.java
@@ -154,20 +154,21 @@
     try (Timer1.Context<String> ctx =
         codeOwnerMetrics.addChangeMessageOnAddReviewer.start(
             asynchronous ? "asynchronous" : "synchronous")) {
-      retryHelper
-          .changeUpdate(
-              "addCodeOwnersMessageOnAddReviewer",
-              updateFactory -> {
-                try (BatchUpdate batchUpdate =
-                        updateFactory.create(projectName, currentUser, when);
-                    RefUpdateContext pluginCtx = RefUpdateContext.open(PLUGIN);
-                    RefUpdateContext changeCtx = RefUpdateContext.open(CHANGE_MODIFICATION)) {
-                  batchUpdate.addOp(changeId, new Op(reviewers, maxPathsInChangeMessages));
-                  batchUpdate.execute();
-                }
-                return null;
-              })
-          .call();
+      var unused =
+          retryHelper
+              .changeUpdate(
+                  "addCodeOwnersMessageOnAddReviewer",
+                  updateFactory -> {
+                    try (BatchUpdate batchUpdate =
+                            updateFactory.create(projectName, currentUser, when);
+                        RefUpdateContext pluginCtx = RefUpdateContext.open(PLUGIN);
+                        RefUpdateContext changeCtx = RefUpdateContext.open(CHANGE_MODIFICATION)) {
+                      batchUpdate.addOp(changeId, new Op(reviewers, maxPathsInChangeMessages));
+                      batchUpdate.execute();
+                    }
+                    return null;
+                  })
+              .call();
     } catch (Exception e) {
       Optional<? extends Exception> configurationError =
           CodeOwnersExceptionHook.getCauseOfConfigurationError(e);
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersUpdate.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersUpdate.java
index 5e41d70..a3e91e3 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersUpdate.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnersUpdate.java
@@ -14,6 +14,7 @@
 
 package com.google.gerrit.plugins.codeowners.backend;
 
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
 import com.google.gerrit.plugins.codeowners.backend.config.CodeOwnersPluginConfiguration;
 import com.google.gerrit.server.IdentifiedUser;
 import com.google.inject.assistedinject.Assisted;
@@ -93,6 +94,7 @@
    * @return the updated/created code owner config, {@link Optional#empty()} if the update led to a
    *     deletion of the code owner config or if the creation was a no-op
    */
+  @CanIgnoreReturnValue
   public Optional<CodeOwnerConfig> upsertCodeOwnerConfig(
       CodeOwnerConfig.Key codeOwnerConfigKey, CodeOwnerConfigUpdate codeOwnerConfigUpdate) {
     CodeOwnerBackend codeOwnerBackend =
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerApproval.java b/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerApproval.java
index ab700ec..3650c96 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerApproval.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/OnCodeOwnerApproval.java
@@ -256,29 +256,30 @@
       RequiredApproval requiredApproval,
       int maxPathsInChangeMessages) {
     try (Timer0.Context ctx = codeOwnerMetrics.addChangeMessageOnCodeOwnerApproval.start()) {
-      retryHelper
-          .changeUpdate(
-              "addCodeOwnersMessageOnCodeOwnerApproval",
-              updateFactory -> {
-                try (BatchUpdate batchUpdate =
-                        updateFactory.create(changeNotes.getProjectName(), user, when);
-                    RefUpdateContext pluginCtx = RefUpdateContext.open(PLUGIN);
-                    RefUpdateContext changeCtx = RefUpdateContext.open(CHANGE_MODIFICATION)) {
-                  batchUpdate.addOp(
-                      changeNotes.getChangeId(),
-                      new Op(
-                          user,
-                          changeNotes,
-                          patchSet,
-                          oldApprovals,
-                          approvals,
-                          requiredApproval,
-                          maxPathsInChangeMessages));
-                  batchUpdate.execute();
-                }
-                return null;
-              })
-          .call();
+      var unused =
+          retryHelper
+              .changeUpdate(
+                  "addCodeOwnersMessageOnCodeOwnerApproval",
+                  updateFactory -> {
+                    try (BatchUpdate batchUpdate =
+                            updateFactory.create(changeNotes.getProjectName(), user, when);
+                        RefUpdateContext pluginCtx = RefUpdateContext.open(PLUGIN);
+                        RefUpdateContext changeCtx = RefUpdateContext.open(CHANGE_MODIFICATION)) {
+                      batchUpdate.addOp(
+                          changeNotes.getChangeId(),
+                          new Op(
+                              user,
+                              changeNotes,
+                              patchSet,
+                              oldApprovals,
+                              approvals,
+                              requiredApproval,
+                              maxPathsInChangeMessages));
+                      batchUpdate.execute();
+                    }
+                    return null;
+                  })
+              .call();
     } catch (Exception e) {
       Optional<? extends Exception> configurationError =
           CodeOwnersExceptionHook.getCauseOfConfigurationError(e);
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnerStatus.java b/java/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnerStatus.java
index 6942268..665dd56 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnerStatus.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnerStatus.java
@@ -19,6 +19,7 @@
 import com.google.auto.value.AutoValue;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
 import com.google.gerrit.common.Nullable;
 import com.google.gerrit.entities.Account;
 import com.google.gerrit.plugins.codeowners.common.CodeOwnerStatus;
@@ -151,6 +152,7 @@
     abstract Builder setOwners(Optional<ImmutableSet<Account.Id>> owners);
 
     /** Adds a reason for this status. */
+    @CanIgnoreReturnValue
     public Builder addReason(String reason) {
       reasonsBuilder().add(reason);
       return this;
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/config/AbstractRequiredApprovalConfig.java b/java/com/google/gerrit/plugins/codeowners/backend/config/AbstractRequiredApprovalConfig.java
index 59cce10..f5ce964 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/config/AbstractRequiredApprovalConfig.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/config/AbstractRequiredApprovalConfig.java
@@ -117,7 +117,7 @@
     ImmutableList.Builder<CommitValidationMessage> validationMessages = ImmutableList.builder();
     for (String requiredApproval : requiredApprovals) {
       try {
-        RequiredApproval.parse(projectState, requiredApproval);
+        var unused = RequiredApproval.parse(projectState, requiredApproval);
       } catch (IllegalArgumentException | IllegalStateException e) {
         validationMessages.add(
             new CommitValidationMessage(
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/config/StatusConfig.java b/java/com/google/gerrit/plugins/codeowners/backend/config/StatusConfig.java
index d75a3fa..a6789c3 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/config/StatusConfig.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/config/StatusConfig.java
@@ -99,7 +99,7 @@
     for (String refPattern :
         projectLevelConfig.getStringList(SECTION_CODE_OWNERS, null, KEY_DISABLED_BRANCH)) {
       try {
-        RefPatternMatcher.getMatcher(refPattern).match("refs/heads/master", null);
+        var unused = RefPatternMatcher.getMatcher(refPattern).match("refs/heads/master", null);
       } catch (PatternSyntaxException e) {
         validationMessages.add(
             new CommitValidationMessage(
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/findowners/ParsedEmailLine.java b/java/com/google/gerrit/plugins/codeowners/backend/findowners/ParsedEmailLine.java
index 19d5004..5d019be 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/findowners/ParsedEmailLine.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/findowners/ParsedEmailLine.java
@@ -18,6 +18,7 @@
 
 import com.google.auto.value.AutoValue;
 import com.google.common.collect.ImmutableSet;
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
 import com.google.gerrit.plugins.codeowners.backend.CodeOwnerAnnotation;
 import com.google.gerrit.plugins.codeowners.backend.CodeOwnerReference;
 
@@ -43,6 +44,7 @@
 
     abstract ImmutableSet.Builder<CodeOwnerAnnotation> annotationsBuilder();
 
+    @CanIgnoreReturnValue
     Builder addAnnotation(String annotation) {
       requireNonNull(annotation, "annotation");
       annotationsBuilder().add(CodeOwnerAnnotation.create(annotation));
diff --git a/java/com/google/gerrit/plugins/codeowners/testing/backend/TestCodeOwnerConfigStorage.java b/java/com/google/gerrit/plugins/codeowners/testing/backend/TestCodeOwnerConfigStorage.java
index 772277b..9cd085a 100644
--- a/java/com/google/gerrit/plugins/codeowners/testing/backend/TestCodeOwnerConfigStorage.java
+++ b/java/com/google/gerrit/plugins/codeowners/testing/backend/TestCodeOwnerConfigStorage.java
@@ -14,6 +14,7 @@
 
 package com.google.gerrit.plugins.codeowners.testing.backend;
 
+import com.google.errorprone.annotations.CanIgnoreReturnValue;
 import com.google.gerrit.plugins.codeowners.backend.CodeOwnerConfig;
 import com.google.gerrit.plugins.codeowners.backend.CodeOwnerConfigParser;
 import com.google.gerrit.plugins.codeowners.util.JgitPath;
@@ -62,6 +63,7 @@
    *     config properties should be set
    * @return the code owner config that was written
    */
+  @CanIgnoreReturnValue
   public CodeOwnerConfig writeCodeOwnerConfig(
       CodeOwnerConfig.Key codeOwnerConfigKey,
       Consumer<CodeOwnerConfig.Builder> codeOwnerConfigUpdater)
diff --git a/java/com/google/gerrit/plugins/codeowners/validation/CodeOwnerConfigValidator.java b/java/com/google/gerrit/plugins/codeowners/validation/CodeOwnerConfigValidator.java
index 91a8c56..f6c3d26 100644
--- a/java/com/google/gerrit/plugins/codeowners/validation/CodeOwnerConfigValidator.java
+++ b/java/com/google/gerrit/plugins/codeowners/validation/CodeOwnerConfigValidator.java
@@ -823,7 +823,7 @@
         // there.
         CodeOwnerConfig.Key baseCodeOwnerConfigKey =
             createCodeOwnerConfigKey(branchNameKey, changedFile.oldPath().get());
-        codeOwnerBackend.getCodeOwnerConfig(baseCodeOwnerConfigKey, parentRevision);
+        var unused = codeOwnerBackend.getCodeOwnerConfig(baseCodeOwnerConfigKey, parentRevision);
         // The code owner config at the parent revision is parseable. This means the parsing error
         // is introduced by the new commit and we should block uploading it, which we achieve by
         // setting the validation message type to fatal.
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java
index 5cc69d3..98a72ad 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java
@@ -1228,7 +1228,7 @@
   @Test
   @GerritConfig(name = "accounts.visibility", value = "NONE")
   public void getAllUsersAsCodeOwners_noneVisible() throws Exception {
-    accountCreator.user2();
+    var unused = accountCreator.user2();
 
     // Add a code owner config that makes all users code owners.
     codeOwnerConfigOperations
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/BUILD b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/BUILD
index a4fd76e..1f58358 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/BUILD
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/BUILD
@@ -1,3 +1,4 @@
+load("@rules_java//java:defs.bzl", "java_library")
 load("//javatests/com/google/gerrit/acceptance:tests.bzl", "acceptance_tests")
 
 package(
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerConfigValidatorIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerConfigValidatorIT.java
index ebf79b9..009fd2e 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerConfigValidatorIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerConfigValidatorIT.java
@@ -2345,7 +2345,7 @@
     cherryPickInput.validationOptions =
         ImmutableMap.of(
             String.format("code-owners~%s", SkipCodeOwnerConfigValidationPushOption.NAME), "true");
-    gApi.changes().id(r.getChangeId()).current().cherryPickAsInfo(cherryPickInput);
+    var unused = gApi.changes().id(r.getChangeId()).current().cherryPickAsInfo(cherryPickInput);
   }
 
   @Test
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerSubmitRuleIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerSubmitRuleIT.java
index 7275f4f..159ae18 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerSubmitRuleIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerSubmitRuleIT.java
@@ -695,9 +695,10 @@
     String changeId = r.getChangeId();
 
     testMetricMaker.reset();
-    gApi.changes()
-        .id(changeId)
-        .get(ListChangesOption.ALL_REVISIONS, ListChangesOption.CURRENT_ACTIONS);
+    var unused =
+        gApi.changes()
+            .id(changeId)
+            .get(ListChangesOption.ALL_REVISIONS, ListChangesOption.CURRENT_ACTIONS);
 
     // Submit rules are computed freshly, but only once.
     assertThat(testMetricMaker.getCount("plugins/code-owners/count_code_owner_submit_rule_runs"))
@@ -720,9 +721,10 @@
     String changeId = r.getChangeId();
 
     testMetricMaker.reset();
-    gApi.changes()
-        .id(changeId)
-        .get(ListChangesOption.ALL_REVISIONS, ListChangesOption.CURRENT_ACTIONS);
+    var unused =
+        gApi.changes()
+            .id(changeId)
+            .get(ListChangesOption.ALL_REVISIONS, ListChangesOption.CURRENT_ACTIONS);
 
     // Submit rules are computed freshly, but only once.
     assertThat(testMetricMaker.getCount("plugins/code-owners/count_code_owner_submit_rule_runs"))
@@ -784,10 +786,11 @@
     String changeId = r.getChangeId();
 
     testMetricMaker.reset();
-    gApi.changes()
-        .query(changeId)
-        .withOptions(ListChangesOption.ALL_REVISIONS, ListChangesOption.CURRENT_ACTIONS)
-        .get();
+    var unused =
+        gApi.changes()
+            .query(changeId)
+            .withOptions(ListChangesOption.ALL_REVISIONS, ListChangesOption.CURRENT_ACTIONS)
+            .get();
 
     // Submit rule evaluation results from the change index are reused
     assertThat(testMetricMaker.getCount("plugins/code-owners/count_code_owner_submit_rule_runs"))
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/GetOwnedPathsIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/GetOwnedPathsIT.java
index 54a94a1..4349f19 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/GetOwnedPathsIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/GetOwnedPathsIT.java
@@ -152,16 +152,17 @@
     String path2 = "/foo/baz/bar.md";
     String path3 = "/bar/foo.md";
 
-    createChange(
-            "Change Adding Files",
-            ImmutableMap.of(
-                JgitPath.of(path1).get(),
-                "file content 1",
-                JgitPath.of(path2).get(),
-                "file content 2",
-                JgitPath.of(path3).get(),
-                "file content 3"))
-        .getChangeId();
+    var unused =
+        createChange(
+                "Change Adding Files",
+                ImmutableMap.of(
+                    JgitPath.of(path1).get(),
+                    "file content 1",
+                    JgitPath.of(path2).get(),
+                    "file content 2",
+                    JgitPath.of(path3).get(),
+                    "file content 3"))
+            .getChangeId();
 
     PushOneCommit push =
         pushFactory.create(
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerApprovalIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerApprovalIT.java
index 7feee40..167037b 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerApprovalIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerApprovalIT.java
@@ -159,7 +159,7 @@
       throws Exception {
     LabelDefinitionInput input = new LabelDefinitionInput();
     input.values = ImmutableMap.of("+1", "Other", " 0", "Approved");
-    gApi.projects().name(project.get()).label("Other").create(input).get();
+    var unused = gApi.projects().name(project.get()).label("Other").create(input).get();
 
     projectOperations
         .project(project)
@@ -208,7 +208,7 @@
       throws Exception {
     LabelDefinitionInput input = new LabelDefinitionInput();
     input.values = ImmutableMap.of("+1", "Other", " 0", "Approved");
-    gApi.projects().name(project.get()).label("Other").create(input).get();
+    var unused = gApi.projects().name(project.get()).label("Other").create(input).get();
 
     projectOperations
         .project(project)
@@ -575,7 +575,7 @@
   public void changeMessageNotExtendedForNonCodeOwnerApproval() throws Exception {
     LabelDefinitionInput input = new LabelDefinitionInput();
     input.values = ImmutableMap.of("+1", "Owner Approval", " 0", "No Owner Approval");
-    gApi.projects().name(project.get()).label("Owners-Approval").create(input).get();
+    var unused = gApi.projects().name(project.get()).label("Owners-Approval").create(input).get();
 
     codeOwnerConfigOperations
         .newCodeOwnerConfig()
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerOverrrideIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerOverrrideIT.java
index 9997432..61dff07 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerOverrrideIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/OnCodeOwnerOverrrideIT.java
@@ -134,7 +134,7 @@
   public void changeMessageExtendedIfCodeOwnersOverrideIsUpgraded() throws Exception {
     LabelDefinitionInput input = new LabelDefinitionInput();
     input.values = ImmutableMap.of("+2", "Override", "+1", "Override", " 0", "No Override");
-    gApi.projects().name(project.get()).label("Owners-Override").create(input).get();
+    var unused = gApi.projects().name(project.get()).label("Owners-Override").create(input).get();
 
     // Allow to vote on the Owners-Override label.
     projectOperations
@@ -170,7 +170,7 @@
   public void changeMessageExtendedIfCodeOwnersOverrideIsDowngraded() throws Exception {
     LabelDefinitionInput input = new LabelDefinitionInput();
     input.values = ImmutableMap.of("+2", "Override", "+1", "Override", " 0", "No Override");
-    gApi.projects().name(project.get()).label("Owners-Override").create(input).get();
+    var unused = gApi.projects().name(project.get()).label("Owners-Override").create(input).get();
 
     // Allow to vote on the Owners-Override label.
     projectOperations
@@ -228,7 +228,7 @@
   public void changeMessageExtendedIfCodeOwnersOverrideIsChangedToNegativeValue() throws Exception {
     LabelDefinitionInput input = new LabelDefinitionInput();
     input.values = ImmutableMap.of("+1", "Override", " 0", "No Override", "-1", "No Override");
-    gApi.projects().name(project.get()).label("Owners-Override").create(input).get();
+    var unused = gApi.projects().name(project.get()).label("Owners-Override").create(input).get();
 
     // Allow to vote on the Owners-Override label.
     projectOperations
@@ -264,7 +264,7 @@
   public void changeMessageNotExtendedIfNonCodeOwnersOverrideIsApplied() throws Exception {
     LabelDefinitionInput input = new LabelDefinitionInput();
     input.values = ImmutableMap.of("+1", "Approval", " 0", "No Approval");
-    gApi.projects().name(project.get()).label("Other").create(input).get();
+    var unused = gApi.projects().name(project.get()).label("Other").create(input).get();
 
     // Allow to vote on the Owners-Override label.
     projectOperations
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/PutCodeOwnerProjectConfigIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/PutCodeOwnerProjectConfigIT.java
index ddddf39..4a79844 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/PutCodeOwnerProjectConfigIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/PutCodeOwnerProjectConfigIT.java
@@ -213,7 +213,7 @@
     String otherLabel = "Other";
     LabelDefinitionInput labelInput = new LabelDefinitionInput();
     labelInput.values = ImmutableMap.of("+2", "Approval", "+1", "LGTM", " 0", "No Vote");
-    gApi.projects().name(project.get()).label(otherLabel).create(labelInput).get();
+    var unused = gApi.projects().name(project.get()).label(otherLabel).create(labelInput).get();
 
     CodeOwnerProjectConfigInput input = new CodeOwnerProjectConfigInput();
     input.requiredApproval = otherLabel + "+2";
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/RenameEmailIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/RenameEmailIT.java
index 9238093..176994a 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/RenameEmailIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/RenameEmailIT.java
@@ -539,29 +539,30 @@
             .create();
 
     // insert some comments
-    codeOwnerConfigFileUpdateScanner.update(
-        BranchNameKey.create(project, "master"),
-        "Insert comments",
-        (codeOwnerConfigFilePath, codeOwnerConfigFileContent) -> {
-          StringBuilder b = new StringBuilder();
-          // insert comment line at the top of the file
-          b.append("# top comment\n");
+    var unused =
+        codeOwnerConfigFileUpdateScanner.update(
+            BranchNameKey.create(project, "master"),
+            "Insert comments",
+            (codeOwnerConfigFilePath, codeOwnerConfigFileContent) -> {
+              StringBuilder b = new StringBuilder();
+              // insert comment line at the top of the file
+              b.append("# top comment\n");
 
-          Iterable<String> lines = Splitter.on('\n').split(codeOwnerConfigFileContent);
-          b.append(Iterables.get(lines, /* position= */ 0) + "\n");
+              Iterable<String> lines = Splitter.on('\n').split(codeOwnerConfigFileContent);
+              b.append(Iterables.get(lines, /* position= */ 0) + "\n");
 
-          // insert comment line in the middle of the file
-          b.append("# middle comment\n");
+              // insert comment line in the middle of the file
+              b.append("# middle comment\n");
 
-          for (String line : Iterables.skip(lines, /* numberToSkip= */ 1)) {
-            b.append(line + "\n");
-          }
+              for (String line : Iterables.skip(lines, /* numberToSkip= */ 1)) {
+                b.append(line + "\n");
+              }
 
-          // insert comment line at the bottom of the file
-          b.append("# bottom comment\n");
+              // insert comment line at the bottom of the file
+              b.append("# bottom comment\n");
 
-          return Optional.of(b.toString());
-        });
+              return Optional.of(b.toString());
+            });
 
     String secondaryEmail = "user-foo@example.com";
     accountOperations.account(user.id()).forUpdate().addSecondaryEmail(secondaryEmail).update();
@@ -602,25 +603,26 @@
             .create();
 
     // insert some inline comments
-    codeOwnerConfigFileUpdateScanner.update(
-        BranchNameKey.create(project, "master"),
-        "Insert comments",
-        (codeOwnerConfigFilePath, codeOwnerConfigFileContent) -> {
-          StringBuilder b = new StringBuilder();
-          for (String line : Splitter.on('\n').split(codeOwnerConfigFileContent)) {
-            if (line.contains(user.email())) {
-              b.append(line + "# some comment\n");
-              continue;
-            }
-            if (line.contains(admin.email())) {
-              b.append(line + "# other comment\n");
-              continue;
-            }
-            b.append(line + "\n");
-          }
+    var unused =
+        codeOwnerConfigFileUpdateScanner.update(
+            BranchNameKey.create(project, "master"),
+            "Insert comments",
+            (codeOwnerConfigFilePath, codeOwnerConfigFileContent) -> {
+              StringBuilder b = new StringBuilder();
+              for (String line : Splitter.on('\n').split(codeOwnerConfigFileContent)) {
+                if (line.contains(user.email())) {
+                  b.append(line + "# some comment\n");
+                  continue;
+                }
+                if (line.contains(admin.email())) {
+                  b.append(line + "# other comment\n");
+                  continue;
+                }
+                b.append(line + "\n");
+              }
 
-          return Optional.of(b.toString());
-        });
+              return Optional.of(b.toString());
+            });
 
     String secondaryEmail = "user-foo@example.com";
     accountOperations.account(user.id()).forUpdate().addSecondaryEmail(secondaryEmail).update();
@@ -663,11 +665,12 @@
             .create();
 
     // insert some comments
-    codeOwnerConfigFileUpdateScanner.update(
-        BranchNameKey.create(project, "master"),
-        "Insert comments",
-        (codeOwnerConfigFilePath, codeOwnerConfigFileContent) ->
-            Optional.of("# foo " + user.email() + " bar\n" + codeOwnerConfigFileContent));
+    var unused =
+        codeOwnerConfigFileUpdateScanner.update(
+            BranchNameKey.create(project, "master"),
+            "Insert comments",
+            (codeOwnerConfigFilePath, codeOwnerConfigFileContent) ->
+                Optional.of("# foo " + user.email() + " bar\n" + codeOwnerConfigFileContent));
 
     String secondaryEmail = "user-foo@example.com";
     accountOperations.account(user.id()).forUpdate().addSecondaryEmail(secondaryEmail).update();
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/restapi/BUILD b/javatests/com/google/gerrit/plugins/codeowners/acceptance/restapi/BUILD
index 8593c50..67ac08c 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/restapi/BUILD
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/restapi/BUILD
@@ -1,3 +1,4 @@
+load("@rules_java//java:defs.bzl", "java_library")
 load("//javatests/com/google/gerrit/acceptance:tests.bzl", "acceptance_tests")
 
 package(
diff --git a/javatests/com/google/gerrit/plugins/codeowners/backend/BUILD b/javatests/com/google/gerrit/plugins/codeowners/backend/BUILD
index 5db2a85..c139ec7 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/backend/BUILD
+++ b/javatests/com/google/gerrit/plugins/codeowners/backend/BUILD
@@ -1,3 +1,4 @@
+load("@rules_java//java:defs.bzl", "java_library")
 load("//javatests/com/google/gerrit/acceptance:tests.bzl", "acceptance_tests")
 
 package(
diff --git a/javatests/com/google/gerrit/plugins/codeowners/backend/ChangedFilesTest.java b/javatests/com/google/gerrit/plugins/codeowners/backend/ChangedFilesTest.java
index 02016d8..80538c0 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/backend/ChangedFilesTest.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/backend/ChangedFilesTest.java
@@ -161,7 +161,7 @@
   @Test
   public void getForChangeThatModifiedAFile() throws Exception {
     String path = "/foo/bar/baz.txt";
-    createChange("Test Change", JgitPath.of(path).get(), "file content").getChangeId();
+    var unused = createChange("Test Change", JgitPath.of(path).get(), "file content").getChangeId();
 
     RevCommit commit =
         createChange("Change Modifying A File", JgitPath.of(path).get(), "new file content")
@@ -206,7 +206,7 @@
     String newPath = "/foo/bar/new.txt";
     TestChange change = createChangeWithFileRename(oldPath, newPath);
 
-    gApi.changes().id(change.id()).current().files();
+    var unused = gApi.changes().id(change.id()).current().files();
 
     ImmutableList<ChangedFile> changedFilesSet =
         changedFiles.get(
diff --git a/javatests/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheckInputTest.java b/javatests/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheckInputTest.java
index 9f2a585..4fc1604 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheckInputTest.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheckInputTest.java
@@ -179,7 +179,7 @@
     // Create Foo-Review label.
     LabelDefinitionInput input = new LabelDefinitionInput();
     input.values = ImmutableMap.of("+1", "Approved", " 0", "Not Approved");
-    gApi.projects().name(project.get()).label("Foo-Review").create(input).get();
+    var unused = gApi.projects().name(project.get()).label("Foo-Review").create(input).get();
 
     // Allow to vote on the Foo-Review label.
     projectOperations
diff --git a/javatests/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheckTest.java b/javatests/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheckTest.java
index 951786e..b95fb30 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheckTest.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/backend/CodeOwnerApprovalCheckTest.java
@@ -115,7 +115,7 @@
     TestAccount user2 = accountCreator.user2();
 
     Path path = Path.of("/foo/bar.baz");
-    createChange("Test Change", JgitPath.of(path).get(), "file content").getChangeId();
+    var unused = createChange("Test Change", JgitPath.of(path).get(), "file content").getChangeId();
     String changeId =
         createChange("Change Modifying A File", JgitPath.of(path).get(), "new file content")
             .getChangeId();
@@ -215,7 +215,7 @@
     setAsRootCodeOwners(user);
 
     Path path = Path.of("/foo/bar.baz");
-    createChange("Test Change", JgitPath.of(path).get(), "file content").getChangeId();
+    var unused = createChange("Test Change", JgitPath.of(path).get(), "file content").getChangeId();
     String changeId =
         createChange("Change Modifying A File", JgitPath.of(path).get(), "new file content")
             .getChangeId();
@@ -358,7 +358,7 @@
     setAsRootCodeOwners(user);
 
     Path path = Path.of("/foo/bar.baz");
-    createChange("Test Change", JgitPath.of(path).get(), "file content").getChangeId();
+    var unused = createChange("Test Change", JgitPath.of(path).get(), "file content").getChangeId();
     String changeId =
         createChange("Change Modifying A File", JgitPath.of(path).get(), "new file content")
             .getChangeId();
@@ -1868,7 +1868,7 @@
   public void ownersOverridePlus2CountsAsOverrideIfOverridePlus1IsRequired() throws Exception {
     LabelDefinitionInput input = new LabelDefinitionInput();
     input.values = ImmutableMap.of("+2", "Override+2", "+1", "Override", " 0", "No Override");
-    gApi.projects().name(project.get()).label("Owners-Override").create(input).get();
+    var unused = gApi.projects().name(project.get()).label("Owners-Override").create(input).get();
 
     // Allow to vote on the Owners-Override label.
     projectOperations
diff --git a/javatests/com/google/gerrit/plugins/codeowners/backend/config/BUILD b/javatests/com/google/gerrit/plugins/codeowners/backend/config/BUILD
index 9dc820d..ca03ea5 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/backend/config/BUILD
+++ b/javatests/com/google/gerrit/plugins/codeowners/backend/config/BUILD
@@ -1,3 +1,4 @@
+load("@rules_java//java:defs.bzl", "java_library")
 load("//javatests/com/google/gerrit/acceptance:tests.bzl", "acceptance_tests")
 
 package(
diff --git a/javatests/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginProjectConfigSnapshotTest.java b/javatests/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginProjectConfigSnapshotTest.java
index 77f79bf..15b51d7 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginProjectConfigSnapshotTest.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/backend/config/CodeOwnersPluginProjectConfigSnapshotTest.java
@@ -1549,7 +1549,7 @@
       throws Exception {
     LabelDefinitionInput input = new LabelDefinitionInput();
     input.values = ImmutableMap.of("+2", "Super-Override", "+1", "Override", " 0", "No Override");
-    gApi.projects().name(project.get()).label("Owners-Override").create(input).get();
+    var unused = gApi.projects().name(project.get()).label("Owners-Override").create(input).get();
 
     configureOverrideApproval(allProjects, "Owners-Override+1");
     configureOverrideApproval(project, "Owners-Override+2");
diff --git a/proto/BUILD b/proto/BUILD
index 59bba8a..d6f290f 100644
--- a/proto/BUILD
+++ b/proto/BUILD
@@ -1,5 +1,5 @@
 load("@protobuf//bazel:java_proto_library.bzl", "java_proto_library")
-load("@rules_proto//proto:defs.bzl", "proto_library")
+load("@protobuf//bazel:proto_library.bzl", "proto_library")
 
 proto_library(
     name = "owners_metadata_proto",