JDK-8241151 : Incorrect lint warning for no definition of serialVersionUID in a record
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 14,15,16
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-03-18
  • Updated: 2020-10-05
  • Resolved: 2020-09-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 16
16 b18Fixed
Related Reports
Relates :  
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

Comments
Changeset: ac15d644 Author: Vicente Romero <vromero@openjdk.org> Date: 2020-09-28 21:20:14 +0000 URL: https://git.openjdk.java.net/jdk/commit/ac15d644
28-09-2020

Here is a potential fix which removes this lint warning for records on jdk14u (langtools:tier1 is OK): diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -5220,8 +5220,8 @@ } if (svuid == null) { - log.warning(LintCategory.SERIAL, - tree.pos(), Warnings.MissingSVUID(c)); + if (!c.isRecord()) + log.warning(LintCategory.SERIAL, tree.pos(), Warnings.MissingSVUID(c)); return; }
23-09-2020

Raised (again) on amber-dev: https://mail.openjdk.java.net/pipermail/amber-dev/2020-August/thread.html#6407
04-08-2020