Merge branch 'stable-3.3' into stable-3.4

* stable-3.3:
  Return 400 when deleting/creating an invalid project name

Change-Id: Ic51d36acf6e884acff15cd78b1efbecf61c17f83
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java
index 8c47801..20122a7 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/PullReplicationFilter.java
@@ -56,6 +56,7 @@
 import java.io.EOFException;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.nio.file.InvalidPathException;
 import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Optional;
@@ -158,7 +159,12 @@
       RestApiServlet.replyError(
           httpRequest, httpResponse, SC_BAD_REQUEST, "Project name not present in the url", e);
     } catch (Exception e) {
-      throw new ServletException(e);
+      if (e instanceof InvalidPathException || e.getCause() instanceof InvalidPathException) {
+        RestApiServlet.replyError(
+            httpRequest, httpResponse, SC_BAD_REQUEST, "Invalid repository path in request", e);
+      } else {
+        throw new ServletException(e);
+      }
     }
   }
 
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectDeletionActionIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectDeletionActionIT.java
index 2953ed0..a46a721 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectDeletionActionIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectDeletionActionIT.java
@@ -23,6 +23,7 @@
 import com.google.inject.Inject;
 import javax.servlet.http.HttpServletResponse;
 import org.apache.http.client.methods.HttpRequestBase;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class ProjectDeletionActionIT extends ActionITBase {
@@ -75,14 +76,15 @@
   }
 
   @Test
-  public void shouldReturnInternalServerErrorIfProjectCannotBeDeleted() throws Exception {
+  @Ignore("Failing in RestApiServlet: to be enabled again once that is fixed in core")
+  public void shouldReturnBadRequestWhenDeletingAnInvalidProjectName() throws Exception {
     url = getURLWithAuthenticationPrefix(INVALID_TEST_PROJECT_NAME);
 
     httpClientFactory
         .create(source)
         .execute(
             withBasicAuthenticationAsAdmin(createDeleteRequest()),
-            assertHttpResponseCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
+            assertHttpResponseCode(HttpServletResponse.SC_BAD_REQUEST));
   }
 
   @Test
@@ -131,7 +133,7 @@
 
   @Test
   @GerritConfig(name = "container.replica", value = "true")
-  public void shouldReturnInternalServerErrorIfProjectCannotBeDeletedWhenNodeIsAReplica()
+  public void shouldReturnBadRequestWhenDeletingAnInvalidProjectNameWhenNodeIsAReplica()
       throws Exception {
     url = getURLWithAuthenticationPrefix(INVALID_TEST_PROJECT_NAME);
 
@@ -139,7 +141,7 @@
         .create(source)
         .execute(
             withBasicAuthenticationAsAdmin(createDeleteRequest()),
-            assertHttpResponseCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
+            assertHttpResponseCode(HttpServletResponse.SC_BAD_REQUEST));
   }
 
   @Test
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectInitializationActionIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectInitializationActionIT.java
index 99b3336..77f05a1 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectInitializationActionIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ProjectInitializationActionIT.java
@@ -150,14 +150,14 @@
 
   @Test
   @GerritConfig(name = "container.replica", value = "true")
-  public void shouldReturnInternalServerErrorIfProjectCannotBeCreatedWhenNodeIsAReplica()
+  public void shouldReturnBadRequestIfProjectNameIsInvalidAndCannotBeCreatedWhenNodeIsAReplica()
       throws Exception {
     url = getURLWithAuthenticationPrefix(INVALID_TEST_PROJECT_NAME);
     httpClientFactory
         .create(source)
         .execute(
             withBasicAuthenticationAsAdmin(createPutRequestWithHeaders()),
-            assertHttpResponseCode(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
+            assertHttpResponseCode(HttpServletResponse.SC_BAD_REQUEST));
   }
 
   @Test