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

Incorrect lint warning for no definition of serialVersionUID in a record

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 14, 15, 16
    • Fix Version/s: 16
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b18

      Description

      Records are a preview feature of Java SE 14.
        https://docs.oracle.com/en/java/javase/14/docs/specs/index.html

      The Java Object Serialization Specification has a record-preview-feature addendum, that describes serializable records. The requirement for matching the SVUID for a serializable record is waived, see
        https://docs.oracle.com/en/java/javase/14/docs/specs/records-serialization.html#stream-unique-identifiers

        Specifically: "Record classes have a default serialVersionUID value of 0L, but can declare an explicit serialVersionUID. The requirement for matching serialVersionUID values is waived for record classes."

      As such, the absence of a SVUID declaration in a serializable record's source code should not result in a lint warning. For example:

      $ ./jdk-14.jdk/Contents/Home/bin/java -version
      openjdk version "14" 2020-03-17
      OpenJDK Runtime Environment (build 14+36-1461)
      OpenJDK 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)
      $
      $ cat SerializablePoint.java
      public record SerializablePoint (int x, int y) implements java.io.Serializable { }
      $
      $ ./jdk-14.jdk/Contents/Home/bin/javac -Xlint:serial --release 14 --enable-preview SerializablePoint.java
      SerializablePoint.java:1: warning: [serial] serializable class SerializablePoint has no definition of serialVersionUID
      public record SerializablePoint (int x, int y) implements java.io.Serializable { }
             ^
      Note: SerializablePoint.java uses preview language features.
      Note: Recompile with -Xlint:preview for details.
      1 warning

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bsrbnd Bernard Blaser
              Reporter:
              chegar Chris Hegarty
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: