Fix removal of inherited global code owners

Global code owners that are configured on parent projects are inherited,
but projects can override them. Projects should also be able to remove
the inherited global code owners by configuring an empty value for
global code owners (same as it already works for exempted users).

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I1992e55573ed49188e315d34b43c7ce8821ad4cb
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/config/GeneralConfig.java b/java/com/google/gerrit/plugins/codeowners/backend/config/GeneralConfig.java
index 251504a..f1505c0 100644
--- a/java/com/google/gerrit/plugins/codeowners/backend/config/GeneralConfig.java
+++ b/java/com/google/gerrit/plugins/codeowners/backend/config/GeneralConfig.java
@@ -563,11 +563,13 @@
       return Arrays.stream(
               pluginConfig.getStringList(
                   SECTION_CODE_OWNERS, /* subsection= */ null, KEY_GLOBAL_CODE_OWNER))
+          .filter(value -> !value.trim().isEmpty())
           .map(CodeOwnerReference::create)
           .collect(toImmutableSet());
     }
 
     return Arrays.stream(pluginConfigFromGerritConfig.getStringList(KEY_GLOBAL_CODE_OWNER))
+        .filter(value -> !value.trim().isEmpty())
         .map(CodeOwnerReference::create)
         .collect(toImmutableSet());
   }
diff --git a/javatests/com/google/gerrit/plugins/codeowners/backend/config/GeneralConfigTest.java b/javatests/com/google/gerrit/plugins/codeowners/backend/config/GeneralConfigTest.java
index ed66d23..456deb5 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/backend/config/GeneralConfigTest.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/backend/config/GeneralConfigTest.java
@@ -714,6 +714,16 @@
   }
 
   @Test
+  @GerritConfig(
+      name = "plugin.code-owners.globalCodeOwner",
+      values = {"bot1@example.com", "bot2@example.com"})
+  public void inheritedGlobalOwnersCanBeRemovedOnProjectLevel() throws Exception {
+    Config cfg = new Config();
+    cfg.setString(SECTION_CODE_OWNERS, /* subsection= */ null, KEY_GLOBAL_CODE_OWNER, "");
+    assertThat(generalConfig.getGlobalCodeOwners(cfg)).isEmpty();
+  }
+
+  @Test
   public void cannotGetExemptedUsersForNullPluginConfig() throws Exception {
     NullPointerException npe =
         assertThrows(