# HG changeset patch # User martin # Date 1512335211 28800 # Sun Dec 03 13:06:51 2017 -0800 # Node ID 409e970f062a1d570a8c785ae1c5941cb208a0f9 # Parent b1993e334da1d50d5713e73e2696432bc4ce9ac1 8192935: Fix EnumSet's SerializationProxy javadoc Reviewed-by: smarks, rriggs diff --git a/src/java.base/share/classes/java/util/EnumSet.java b/src/java.base/share/classes/java/util/EnumSet.java --- a/src/java.base/share/classes/java/util/EnumSet.java +++ b/src/java.base/share/classes/java/util/EnumSet.java @@ -75,7 +75,6 @@ * @author Josh Bloch * @since 1.5 * @see EnumMap - * @serial exclude */ @SuppressWarnings("serial") // No serialVersionUID due to usage of // serial proxy pattern @@ -85,12 +84,12 @@ /** * The class of all the elements of this set. */ - final Class elementType; + final transient Class elementType; /** - * All of the values comprising T. (Cached for performance.) + * All of the values comprising E. (Cached for performance.) */ - final Enum[] universe; + final transient Enum[] universe; EnumSet(ClasselementType, Enum[] universe) { this.elementType = elementType; @@ -416,7 +415,7 @@ * * @serial include */ - private static class SerializationProxy > + private static class SerializationProxy> implements java.io.Serializable { @@ -441,10 +440,18 @@ elements = set.toArray(ZERO_LENGTH_ENUM_ARRAY); } - // instead of cast to E, we should perhaps use elementType.cast() - // to avoid injection of forged stream, but it will slow the implementation + /** + * Returns an {@code EnumSet} object with initial state + * held by this proxy. + * + * @return a {@code EnumSet} object with initial state + * held by this proxy + */ @SuppressWarnings("unchecked") private Object readResolve() { + // instead of cast to E, we should perhaps use elementType.cast() + // to avoid injection of forged stream, but it will slow the + // implementation EnumSet result = EnumSet.noneOf(elementType); for (Enum e : elements) result.add((E)e); @@ -454,13 +461,24 @@ private static final long serialVersionUID = 362491234563181265L; } + /** + * Returns a + * + * SerializationProxy + * representing the state of this instance. + * + * @return a {@link SerializationProxy} + * representing the state of this instance + */ Object writeReplace() { return new SerializationProxy<>(this); } - // readObject method for the serialization proxy pattern - // See Effective Java, Second Ed., Item 78. - private void readObject(java.io.ObjectInputStream stream) + /** + * @param s the stream + * @throws java.io.InvalidObjectException always + */ + private void readObject(java.io.ObjectInputStream s) throws java.io.InvalidObjectException { throw new java.io.InvalidObjectException("Proxy required"); } diff --git a/test/jdk/java/util/EnumSet/BogusEnumSet.java b/test/jdk/java/util/EnumSet/BogusEnumSet.java --- a/test/jdk/java/util/EnumSet/BogusEnumSet.java +++ b/test/jdk/java/util/EnumSet/BogusEnumSet.java @@ -34,7 +34,7 @@ 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 + // The current value is -2409567991088730183L = 0xde8f7eadb5012fb9L // If the value changes, it will have to be patched into the // serialized byte stream below at the location noted. byte[] serializedForm = { @@ -47,7 +47,7 @@ 0x11, 0x6a, 0x61, 0x76, 0x61, 0x2e, 0x75, 0x74, 0x69, 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, + (byte)0xde, (byte)0x8f, 0x7e, (byte)0xad, (byte)0xb5, (byte)0x01, 0x2f, (byte)0xb9, 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,