Merge branch 'stable-3.1' into stable-3.2

* stable-3.1:
  Add Gatling e2e-test for rename-project
  Bump Bazel version to 3.5.0

Change-Id: I8d03a6b4974fd262cb0f5da13479fc0985128385
diff --git a/WORKSPACE b/WORKSPACE
index 0abed59..de03f22 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
 load("//:bazlets.bzl", "load_bazlets")
 
 load_bazlets(
-    commit = "3f9dadc615dc4053369a42d9ada37dafd8d4763c",
+    commit = "0f81174e3d1b892a1342ebc75bb4bbb158ae0efe",
     #local_path = "/home/<user>/projects/bazlets",
 )
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameCommand.java b/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameCommand.java
index fce6fa8..6a80283 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/renameproject/RenameCommand.java
@@ -32,6 +32,7 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.List;
+import java.util.NoSuchElementException;
 import java.util.Optional;
 import org.kohsuke.args4j.Argument;
 import org.slf4j.Logger;
@@ -72,7 +73,7 @@
           stdout.flush();
         }
       }
-    } catch (RestApiException | IOException e) {
+    } catch (NoSuchElementException | RestApiException | IOException e) {
       throw die(e);
     }
   }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/renameproject/conditions/RenamePreconditions.java b/src/main/java/com/googlesource/gerrit/plugins/renameproject/conditions/RenamePreconditions.java
index 204c564..cab2957 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/renameproject/conditions/RenamePreconditions.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/renameproject/conditions/RenamePreconditions.java
@@ -25,7 +25,7 @@
 import com.google.gerrit.server.project.ProjectResource;
 import com.google.gerrit.server.restapi.project.ListChildProjects;
 import com.google.gerrit.server.submit.MergeOpRepoManager;
-import com.google.gerrit.server.submit.SubmoduleException;
+import com.google.gerrit.server.submit.SubmoduleConflictException;
 import com.google.gerrit.server.submit.SubmoduleOp;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
@@ -121,7 +121,7 @@
           throw new CannotRenameProjectException(message);
         }
       }
-    } catch (IOException | SubmoduleException e) {
+    } catch (IOException | SubmoduleConflictException e) {
       throw new CannotRenameProjectException(e);
     }
   }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/renameproject/LockUnlockProjectTest.java b/src/test/java/com/googlesource/gerrit/plugins/renameproject/LockUnlockProjectTest.java
index aa3776f..02c47c5 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/renameproject/LockUnlockProjectTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/renameproject/LockUnlockProjectTest.java
@@ -34,10 +34,13 @@
 
   @Test
   public void testLockUnlockSucceeds() throws IOException, ConfigInvalidException {
-    assertThat(projectCache.get(project).getProject().getState()).isEqualTo(ProjectState.ACTIVE);
+    assertThat(projectCache.get(project).get().getProject().getState())
+        .isEqualTo(ProjectState.ACTIVE);
     lockUnlockInstance.lock(project);
-    assertThat(projectCache.get(project).getProject().getState()).isEqualTo(ProjectState.READ_ONLY);
+    assertThat(projectCache.get(project).get().getProject().getState())
+        .isEqualTo(ProjectState.READ_ONLY);
     lockUnlockInstance.unlock(project);
-    assertThat(projectCache.get(project).getProject().getState()).isEqualTo(ProjectState.ACTIVE);
+    assertThat(projectCache.get(project).get().getProject().getState())
+        .isEqualTo(ProjectState.ACTIVE);
   }
 }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/renameproject/RenameIT.java b/src/test/java/com/googlesource/gerrit/plugins/renameproject/RenameIT.java
index 9fe5a0c..967f5eb 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/renameproject/RenameIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/renameproject/RenameIT.java
@@ -32,6 +32,7 @@
 import com.google.inject.Inject;
 import com.googlesource.gerrit.plugins.renameproject.RenameProject.Input;
 import java.util.List;
+import java.util.Optional;
 import javax.inject.Named;
 import org.eclipse.jgit.junit.TestRepository;
 import org.junit.Test;
@@ -60,8 +61,8 @@
     adminSshSession.exec(PLUGIN_NAME + " " + project.get() + " " + NEW_PROJECT_NAME);
 
     adminSshSession.assertSuccess();
-    ProjectState projectState = projectCache.get(Project.nameKey(NEW_PROJECT_NAME));
-    assertThat(projectState).isNotNull();
+    Optional<ProjectState> projectState = projectCache.get(Project.nameKey(NEW_PROJECT_NAME));
+    assertThat(projectState.isPresent()).isTrue();
     assertThat(queryProvider.get().byProject(project)).isEmpty();
     assertThat(queryProvider.get().byProject(Project.nameKey(NEW_PROJECT_NAME))).isNotEmpty();
   }
@@ -74,8 +75,8 @@
     adminSshSession.exec(PLUGIN_NAME + " " + project.get() + " " + newProjectName);
 
     adminSshSession.assertFailure();
-    ProjectState projectState = projectCache.get(Project.nameKey(newProjectName));
-    assertThat(projectState).isNull();
+    Optional<ProjectState> projectState = projectCache.get(Project.nameKey(newProjectName));
+    assertThat(projectState.isPresent()).isFalse();
   }
 
   @Test
@@ -85,8 +86,8 @@
     adminSshSession.exec(PLUGIN_NAME + " " + allProjects.get() + " " + NEW_PROJECT_NAME);
 
     adminSshSession.assertFailure();
-    ProjectState projectState = projectCache.get(Project.nameKey(NEW_PROJECT_NAME));
-    assertThat(projectState).isNull();
+    Optional<ProjectState> projectState = projectCache.get(Project.nameKey(NEW_PROJECT_NAME));
+    assertThat(projectState.isPresent()).isFalse();
   }
 
   @Test
@@ -159,8 +160,8 @@
     RestResponse r = renameProjectTo(NEW_PROJECT_NAME);
     r.assertOK();
 
-    ProjectState projectState = projectCache.get(Project.nameKey(NEW_PROJECT_NAME));
-    assertThat(projectState).isNotNull();
+    Optional<ProjectState> projectState = projectCache.get(Project.nameKey(NEW_PROJECT_NAME));
+    assertThat(projectState.isPresent()).isTrue();
     assertThat(queryProvider.get().byProject(project)).isEmpty();
     assertThat(queryProvider.get().byProject(Project.nameKey(NEW_PROJECT_NAME))).isNotEmpty();
   }
@@ -173,8 +174,8 @@
     RestResponse r = renameProjectTo(newProjectName);
     r.assertBadRequest();
 
-    ProjectState projectState = projectCache.get(Project.nameKey(newProjectName));
-    assertThat(projectState).isNull();
+    Optional<ProjectState> projectState = projectCache.get(Project.nameKey(newProjectName));
+    assertThat(projectState.isPresent()).isFalse();
   }
 
   private RestResponse renameProjectTo(String newName) throws Exception {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProjectTest.java b/src/test/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProjectTest.java
index b6e6057..f33829d 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProjectTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/renameproject/RevertRenameProjectTest.java
@@ -126,22 +126,22 @@
   }
 
   private void assertReverted() throws Exception {
-    ProjectState oldProjectState = projectCache.get(oldProjectKey);
-    assertThat(oldProjectState).isNotNull();
+    Optional<ProjectState> oldProjectState = projectCache.get(oldProjectKey);
+    assertThat(oldProjectState.isPresent()).isTrue();
 
-    ProjectState newProjectState = projectCache.get(newProjectKey);
-    assertThat(newProjectState).isNull();
+    Optional<ProjectState> newProjectState = projectCache.get(newProjectKey);
+    assertThat(newProjectState.isPresent()).isFalse();
 
     assertThat(queryProvider.get().byProject(oldProjectKey)).isNotEmpty();
     assertThat(queryProvider.get().byProject(newProjectKey)).isEmpty();
   }
 
   private void assertRenamed(Result result) throws Exception {
-    ProjectState oldProjectState = projectCache.get(oldProjectKey);
-    assertThat(oldProjectState).isNull();
+    Optional<ProjectState> oldProjectState = projectCache.get(oldProjectKey);
+    assertThat(oldProjectState.isPresent()).isFalse();
 
-    ProjectState newProjectState = projectCache.get(newProjectKey);
-    assertThat(newProjectState).isNotNull();
+    Optional<ProjectState> newProjectState = projectCache.get(newProjectKey);
+    assertThat(newProjectState.isPresent()).isTrue();
 
     if (renameProject.getStepsPerformed().contains(Step.DATABASE)) {
       ChangeApi changeApi = gApi.changes().id(NEW_PROJECT_NAME, result.getChange().getId().get());