Project.NameKey: Implement Serializable

Prior to Ic46c4a357 the Project.NameKey class extended StringKey and
was implicitly serializable because StringKey implements Serializable.

After Ic46c4a357, Project.NameKey is no longer serializable, which
causes an IllegalStateException when attempting to bind a cache that
uses JavaCacheSerializer with Project.NameKey as key or value.

Add back the Serializable interface and add a test to make sure it is
serializable by JavaCacheSerializer.

Bug: Issue 11793
Change-Id: Id465c3a4cd810de477fb86a13185ec452d5d3a40
diff --git a/java/com/google/gerrit/entities/Project.java b/java/com/google/gerrit/entities/Project.java
index 07f9bc1..ecef87d 100644
--- a/java/com/google/gerrit/entities/Project.java
+++ b/java/com/google/gerrit/entities/Project.java
@@ -19,6 +19,7 @@
 import com.google.gerrit.extensions.client.InheritableBoolean;
 import com.google.gerrit.extensions.client.ProjectState;
 import com.google.gerrit.extensions.client.SubmitType;
+import java.io.Serializable;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
@@ -46,7 +47,9 @@
    * unlike other key types in this package. However, this is strictly an implementation detail; its
    * interface and semantics are otherwise analogous to the {@code @AutoValue} types.
    */
-  public static class NameKey implements Comparable<NameKey> {
+  public static class NameKey implements Serializable, Comparable<NameKey> {
+    private static final long serialVersionUID = 1L;
+
     /** Parse a Project.NameKey out of a string representation. */
     public static NameKey parse(String str) {
       return nameKey(KeyUtil.decode(str));
diff --git a/java/com/google/gerrit/server/config/AllProjectsName.java b/java/com/google/gerrit/server/config/AllProjectsName.java
index bf652a7..6d5525c 100644
--- a/java/com/google/gerrit/server/config/AllProjectsName.java
+++ b/java/com/google/gerrit/server/config/AllProjectsName.java
@@ -18,6 +18,8 @@
 
 /** Special name of the project that all projects derive from. */
 public class AllProjectsName extends Project.NameKey {
+  private static final long serialVersionUID = 1L;
+
   public AllProjectsName(String name) {
     super(name);
   }
diff --git a/java/com/google/gerrit/server/config/AllUsersName.java b/java/com/google/gerrit/server/config/AllUsersName.java
index 16ce43c..aa92db8 100644
--- a/java/com/google/gerrit/server/config/AllUsersName.java
+++ b/java/com/google/gerrit/server/config/AllUsersName.java
@@ -18,6 +18,8 @@
 
 /** Special name of the project in which meta data for all users is stored. */
 public class AllUsersName extends Project.NameKey {
+  private static final long serialVersionUID = 1L;
+
   public AllUsersName(String name) {
     super(name);
   }
diff --git a/javatests/com/google/gerrit/server/cache/serialize/BUILD b/javatests/com/google/gerrit/server/cache/serialize/BUILD
index 81f577e..ce5f273 100644
--- a/javatests/com/google/gerrit/server/cache/serialize/BUILD
+++ b/javatests/com/google/gerrit/server/cache/serialize/BUILD
@@ -4,6 +4,7 @@
     name = "tests",
     srcs = glob(["*.java"]),
     deps = [
+        "//java/com/google/gerrit/entities",
         "//java/com/google/gerrit/server/cache/serialize",
         "//java/com/google/gerrit/server/cache/testing",
         "//java/com/google/gerrit/testing:gerrit-test-util",
diff --git a/javatests/com/google/gerrit/server/cache/serialize/JavaCacheSerializerTest.java b/javatests/com/google/gerrit/server/cache/serialize/JavaCacheSerializerTest.java
index 6596730..effc801 100644
--- a/javatests/com/google/gerrit/server/cache/serialize/JavaCacheSerializerTest.java
+++ b/javatests/com/google/gerrit/server/cache/serialize/JavaCacheSerializerTest.java
@@ -17,6 +17,7 @@
 import static com.google.common.truth.Truth.assertThat;
 
 import com.google.auto.value.AutoValue;
+import com.google.gerrit.entities.Project;
 import java.io.Serializable;
 import org.junit.Test;
 
@@ -33,6 +34,11 @@
     assertRoundTrip(new AutoValue_JavaCacheSerializerTest_MyType(123, "four five six"));
   }
 
+  @Test
+  public void gerritEntities() throws Exception {
+    assertRoundTrip(Project.nameKey("foo"));
+  }
+
   @AutoValue
   abstract static class MyType implements Serializable {
     private static final long serialVersionUID = 1L;