Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8227432

Add serialVersionUID to EnumSet class

XMLWordPrintable

    • behavioral
    • low
    • Hide
      It's rare for class objects to be serialized compared to serialization of instances, though serialization of classes does occur. This change will make the serialization of the EnumSet class in JDK 13 compatible with JDK 8, at the expense of breaking compatibility with JDK 9, 10, 11, and 12. The intent is to backport this fix to a JDK 11 update. While this will cause incompatibility between different versions of JDK 11, the long term result will be that JDK 8, all JDK 11 updates beyond a certain point, and all JDK 13+ releases will be compatible.
      Show
      It's rare for class objects to be serialized compared to serialization of instances, though serialization of classes does occur. This change will make the serialization of the EnumSet class in JDK 13 compatible with JDK 8, at the expense of breaking compatibility with JDK 9, 10, 11, and 12. The intent is to backport this fix to a JDK 11 update. While this will cause incompatibility between different versions of JDK 11, the long term result will be that JDK 8, all JDK 11 updates beyond a certain point, and all JDK 13+ releases will be compatible.
    • Java API, File or wire format
    • SE

      Summary

      Add explicit serialVersionUID declaration to java.util.EnumSet class to match value computed from JDK 8 EnumSet.

      Problem

      JDK 8 did not declare a serialVersionUID for java.util.EnumSet, in the mistaken belief it was unnecessary because of the use of the serialization proxy pattern. The value was thus computed based on the class members. JDK 9 and JDK 10 included changes to the EnumSet class implementation that changed the computed serialVersionUID value. While this doesn't affect serialized instances of EnumSet (because of the proxy) it does affect serialization of the EnumSet class itself. Thus, serialization of the EnumSet class in JDK 8 and earlier releases is incompatible with JDK 9 and later releases.

      Solution

      Add to the EnumSet class a serialVersionUID field initialized to the value corresponding to JDK 8 version of EnumSet

      Specification

      The serialized form of java.util.EnumSet (in serialized-form.html) will declare that its serialVersionUID field has the value 1009687484059888093L:

      private static final long serialVersionUID = 1009687484059888093L;

            plevart Peter Levart
            plevart Peter Levart
            Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: