8148044: Remove Enum[0] constants from EnumSet and EnumMap

Reviewed-by: alanb, chegar, shade, smarks
This commit is contained in:
Claes Redestad 2016-01-25 12:23:55 +01:00
parent 1cbdf12c05
commit 60134cc040
4 changed files with 12 additions and 10 deletions

View file

@ -25,7 +25,6 @@
package java.util; package java.util;
import java.util.Map.Entry;
import jdk.internal.misc.SharedSecrets; import jdk.internal.misc.SharedSecrets;
/** /**
@ -125,8 +124,6 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
return (V)(value == NULL ? null : value); 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. * Creates an empty enum map with the specified key type.
* *

View file

@ -92,8 +92,6 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
*/ */
final Enum<?>[] universe; final Enum<?>[] universe;
private static Enum<?>[] ZERO_LENGTH_ENUM_ARRAY = new Enum<?>[0];
EnumSet(Class<E>elementType, Enum<?>[] universe) { EnumSet(Class<E>elementType, Enum<?>[] universe) {
this.elementType = elementType; this.elementType = elementType;
this.universe = universe; this.universe = universe;
@ -421,6 +419,9 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
private static class SerializationProxy <E extends Enum<E>> private static class SerializationProxy <E extends Enum<E>>
implements java.io.Serializable implements java.io.Serializable
{ {
private static final Enum<?>[] ZERO_LENGTH_ENUM_ARRAY = new Enum<?>[0];
/** /**
* The element type of this enum set. * The element type of this enum set.
* *

View file

@ -48,8 +48,6 @@ public class EnumMapBash {
bash(Silly500.class); bash(Silly500.class);
} }
private static Enum[] ZERO_LENGTH_ENUM_ARRAY = new Enum[0];
static <T extends Enum<T>> void bash(Class<T> enumClass) { static <T extends Enum<T>> void bash(Class<T> enumClass) {
Enum[] universe = enumClass.getEnumConstants(); Enum[] universe = enumClass.getEnumConstants();

View file

@ -32,6 +32,11 @@ import java.io.*;
public class BogusEnumSet { public class BogusEnumSet {
public static void main(String[] args) throws Throwable { 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[] serializedForm = {
(byte)0xac, (byte)0xed, 0x0, 0x5, 0x73, 0x72, 0x0, 0x18, (byte)0xac, (byte)0xed, 0x0, 0x5, 0x73, 0x72, 0x0, 0x18,
0x6a, 0x61, 0x76, 0x61, 0x2e, 0x75, 0x74, 0x69, 0x6a, 0x61, 0x76, 0x61, 0x2e, 0x75, 0x74, 0x69,
@ -40,9 +45,10 @@ public class BogusEnumSet {
0x7e, (byte)0xb0, (byte)0xd0, 0x7e, 0x2, 0x0, 0x1, 0x4a, 0x0, 0x8, 0x7e, (byte)0xb0, (byte)0xd0, 0x7e, 0x2, 0x0, 0x1, 0x4a, 0x0, 0x8,
0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x78, 0x72, 0x0, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x78, 0x72, 0x0,
0x11, 0x6a, 0x61, 0x76, 0x61, 0x2e, 0x75, 0x74, 0x69, 0x11, 0x6a, 0x61, 0x76, 0x61, 0x2e, 0x75, 0x74, 0x69,
0x6c, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x53, 0x65, 0x74, 0xe, 0x6c, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x53, 0x65, 0x74,
0x3, 0x21, 0x6a, (byte)0xcd, (byte)0x8c, 0x29, (byte)0xdd, 0x2, // EnumSet's serialVersionUID is the following eight bytes (big-endian)
0x0, 0x2, 0x4c, 0x0, 0xb, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 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, 0x54, 0x79, 0x70, 0x65, 0x74, 0x0, 0x11, 0x4c, 0x6a, 0x61, 0x76,
0x61, 0x2f, 0x6c, 0x61, 0x6e, 0x67, 0x2f, 0x43, 0x6c, 0x61, 0x73, 0x61, 0x2f, 0x6c, 0x61, 0x6e, 0x67, 0x2f, 0x43, 0x6c, 0x61, 0x73,
0x73, 0x3b, 0x5b, 0x0, 0x8, 0x75, 0x6e, 0x69, 0x76, 0x65, 0x72, 0x73, 0x3b, 0x5b, 0x0, 0x8, 0x75, 0x6e, 0x69, 0x76, 0x65, 0x72,