8148044: Remove Enum[0] constants from EnumSet and EnumMap
authorredestad
Mon, 25 Jan 2016 12:23:55 +0100
changeset 35314 a7e13065a7a0
parent 35313 9e703c485544
child 35315 67dcc46f8241
8148044: Remove Enum[0] constants from EnumSet and EnumMap Reviewed-by: alanb, chegar, shade, smarks
jdk/src/java.base/share/classes/java/util/EnumMap.java
jdk/src/java.base/share/classes/java/util/EnumSet.java
jdk/test/java/util/EnumMap/EnumMapBash.java
jdk/test/java/util/EnumSet/BogusEnumSet.java
--- a/jdk/src/java.base/share/classes/java/util/EnumMap.java	Sun Jan 24 22:27:16 2016 +0000
+++ b/jdk/src/java.base/share/classes/java/util/EnumMap.java	Mon Jan 25 12:23:55 2016 +0100
@@ -25,7 +25,6 @@
 
 package java.util;
 
-import java.util.Map.Entry;
 import jdk.internal.misc.SharedSecrets;
 
 /**
@@ -125,8 +124,6 @@
         return (V)(value == NULL ? null : value);
     }
 
-    private static final Enum<?>[] ZERO_LENGTH_ENUM_ARRAY = new Enum<?>[0];
-
     /**
      * Creates an empty enum map with the specified key type.
      *
--- a/jdk/src/java.base/share/classes/java/util/EnumSet.java	Sun Jan 24 22:27:16 2016 +0000
+++ b/jdk/src/java.base/share/classes/java/util/EnumSet.java	Mon Jan 25 12:23:55 2016 +0100
@@ -92,8 +92,6 @@
      */
     final Enum<?>[] universe;
 
-    private static Enum<?>[] ZERO_LENGTH_ENUM_ARRAY = new Enum<?>[0];
-
     EnumSet(Class<E>elementType, Enum<?>[] universe) {
         this.elementType = elementType;
         this.universe    = universe;
@@ -421,6 +419,9 @@
     private static class SerializationProxy <E extends Enum<E>>
         implements java.io.Serializable
     {
+
+        private static final Enum<?>[] ZERO_LENGTH_ENUM_ARRAY = new Enum<?>[0];
+
         /**
          * The element type of this enum set.
          *
--- a/jdk/test/java/util/EnumMap/EnumMapBash.java	Sun Jan 24 22:27:16 2016 +0000
+++ b/jdk/test/java/util/EnumMap/EnumMapBash.java	Mon Jan 25 12:23:55 2016 +0100
@@ -48,8 +48,6 @@
         bash(Silly500.class);
     }
 
-    private static Enum[] ZERO_LENGTH_ENUM_ARRAY = new Enum[0];
-
     static <T extends Enum<T>> void bash(Class<T> enumClass) {
         Enum[] universe = enumClass.getEnumConstants();
 
--- a/jdk/test/java/util/EnumSet/BogusEnumSet.java	Sun Jan 24 22:27:16 2016 +0000
+++ b/jdk/test/java/util/EnumSet/BogusEnumSet.java	Mon Jan 25 12:23:55 2016 +0100
@@ -32,6 +32,11 @@
 
 public class BogusEnumSet {
     public static void main(String[] args) throws Throwable {
+        // This test depends on the current serialVersionUID of EnumSet,
+        // which may change if the EnumSet class is modified.
+        // The current value is 4168005130090799668L = 0x39D7BA9531116234L
+        // If the value changes, it will have to be patched into the
+        // serialized byte stream below at the location noted.
         byte[] serializedForm  = {
             (byte)0xac, (byte)0xed, 0x0, 0x5, 0x73, 0x72, 0x0, 0x18,
             0x6a,  0x61,  0x76,  0x61, 0x2e,  0x75,  0x74,  0x69,
@@ -40,9 +45,10 @@
             0x7e, (byte)0xb0, (byte)0xd0, 0x7e, 0x2, 0x0, 0x1, 0x4a, 0x0, 0x8,
             0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x78, 0x72, 0x0,
             0x11, 0x6a,  0x61,  0x76,  0x61, 0x2e,  0x75,  0x74,  0x69,
-            0x6c,  0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x53, 0x65, 0x74, 0xe,
-            0x3, 0x21, 0x6a, (byte)0xcd, (byte)0x8c, 0x29, (byte)0xdd, 0x2,
-            0x0, 0x2, 0x4c, 0x0, 0xb, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74,
+            0x6c,  0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x53, 0x65, 0x74,
+            // EnumSet's serialVersionUID is the following eight bytes (big-endian)
+            0x39, (byte)0xd7, (byte)0xba, (byte)0x95, 0x31, 0x11, 0x62, 0x34,
+            0x2, 0x0, 0x2, 0x4c, 0x0, 0xb, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74,
             0x54, 0x79, 0x70, 0x65, 0x74, 0x0, 0x11, 0x4c, 0x6a, 0x61, 0x76,
             0x61, 0x2f, 0x6c, 0x61, 0x6e, 0x67, 0x2f, 0x43, 0x6c, 0x61, 0x73,
             0x73, 0x3b, 0x5b, 0x0, 0x8, 0x75, 0x6e, 0x69, 0x76, 0x65, 0x72,