8234381: API docs should mention special handling of enums in serialization
Reviewed-by: rriggs
--- a/src/java.base/share/classes/java/io/Serializable.java Wed Nov 20 08:12:14 2019 +0800
+++ b/src/java.base/share/classes/java/io/Serializable.java Tue Nov 19 16:26:58 2019 -0800
@@ -134,6 +134,11 @@
* This readResolve method follows the same invocation rules and
* accessibility rules as writeReplace.<p>
*
+ * Enum types are all serializable and receive treatment defined by
+ * the <cite>Java Object Serialization Specification</cite> during
+ * serialization and deserialization. Any declarations of the special
+ * handling methods discussed above are ignored for enum types.<p>
+ *
* The serialization runtime associates with each serializable class a version
* number, called a serialVersionUID, which is used during deserialization to
* verify that the sender and receiver of a serialized object have loaded
@@ -152,8 +157,9 @@
* If a serializable class does not explicitly declare a serialVersionUID, then
* the serialization runtime will calculate a default serialVersionUID value
* for that class based on various aspects of the class, as described in the
- * Java(TM) Object Serialization Specification. However, it is <em>strongly
- * recommended</em> that all serializable classes explicitly declare
+ * Java Object Serialization Specification. This specification defines the
+ * serialVersionUID of an enum type to be 0L. However, it is <em>strongly
+ * recommended</em> that all serializable classes other than enum types explicitly declare
* serialVersionUID values, since the default serialVersionUID computation is
* highly sensitive to class details that may vary depending on compiler
* implementations, and can thus result in unexpected
--- a/src/java.base/share/classes/java/lang/Enum.java Wed Nov 20 08:12:14 2019 +0800
+++ b/src/java.base/share/classes/java/lang/Enum.java Tue Nov 19 16:26:58 2019 -0800
@@ -47,6 +47,13 @@
* found in section 8.9 of
* <cite>The Java™ Language Specification</cite>.
*
+ * Enumeration types are all serializable and receive special handling
+ * by the serialization mechanism. The serialized representation used
+ * for enum constants cannot be customized. Declarations of methods
+ * and fields that would otherwise interact with serialization are
+ * ignored, including {@code serialVersionUID}; see the <cite>Java
+ * Object Serialization Specification</cite> for details.
+ *
* <p> Note that when using an enumeration type as the type of a set
* or as the type of the keys in a map, specialized and efficient
* {@linkplain java.util.EnumSet set} and {@linkplain