Merge "Revert "Extract QueueInfo into its own class"" into stable-3.10
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java
index eae13f2..d5dd6e0 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/FetchOne.java
@@ -635,21 +635,22 @@
         .flatMap(filter -> Optional.ofNullable(filter.get()));
   }
 
-  private Set<FetchRefSpec> runRefsFilter(Set<FetchRefSpec> refs, boolean lock) {
+  private Set<FetchRefSpec> runRefsFilter(Set<FetchRefSpec> refs, boolean lock)
+      throws LockFailureException {
     Set<String> refsNames =
         refs.stream().map(FetchRefSpec::refName).collect(Collectors.toUnmodifiableSet());
-    Set<String> filteredRefNames =
-        replicationFetchFilter()
-            .map(
-                f -> {
-                  if (lock) {
-                    fetchLocks = f.filterAndLock(this.projectName.get(), refsNames);
-                    return fetchLocks.keySet();
-                  } else {
-                    return f.filter(this.projectName.get(), refsNames);
-                  }
-                })
-            .orElse(refsNames);
+    Set<String> filteredRefNames;
+    Optional<ReplicationFetchFilter> fetchFilter = replicationFetchFilter();
+    if (fetchFilter.isPresent()) {
+      if (lock) {
+        fetchLocks = fetchFilter.get().filterAndLock(this.projectName.get(), refsNames);
+        filteredRefNames = fetchLocks.keySet();
+      } else {
+        filteredRefNames = fetchFilter.get().filter(this.projectName.get(), refsNames);
+      }
+    } else {
+      filteredRefNames = refsNames;
+    }
     return refs.stream()
         .filter(refSpec -> filteredRefNames.contains(refSpec.refName()))
         .collect(Collectors.toUnmodifiableSet());
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationFetchFilter.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationFetchFilter.java
index 17afe94..fca499d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationFetchFilter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/ReplicationFetchFilter.java
@@ -15,6 +15,7 @@
 package com.googlesource.gerrit.plugins.replication.pull;
 
 import com.google.gerrit.extensions.annotations.ExtensionPoint;
+import com.googlesource.gerrit.plugins.replication.pull.FetchOne.LockFailureException;
 import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
@@ -29,7 +30,8 @@
 
   Set<String> filter(String projectName, Set<String> fetchRefs);
 
-  default Map<String, AutoCloseable> filterAndLock(String projectName, Set<String> fetchRefs) {
+  default Map<String, AutoCloseable> filterAndLock(String projectName, Set<String> fetchRefs)
+      throws LockFailureException {
     return filter(projectName, fetchRefs).stream()
         .collect(Collectors.toMap(ref -> ref, ref -> () -> {}));
   }