[records] Is serialVersionUID warning for records redundant?

Joe Darcy joe.darcy at oracle.com
Mon Aug 3 21:32:20 UTC 2020


I agree the serial warning should be amended for records. In particular, 
the warning should be if the serializable record has a serialVersionUID 
*defined* since by spec it is zero.  IIRC, there is a case where it 
makes since to have a serialVersionUID in a record for compatibility 
transitioning a class to a record.

HTH,

-Joe

On 8/3/2020 2:23 AM, Remi Forax wrote:
> ----- Mail original -----
>> De: "Tagir Valeev" <amaembo at gmail.com>
>> À: "amber-dev" <amber-dev at openjdk.java.net>
>> Envoyé: Lundi 3 Août 2020 09:30:03
>> Objet: [records] Is serialVersionUID warning for records redundant?
>> Hello!
>>
>> I believe, explicit specification of serialVersionUID in records
>> rarely makes sense and should be discouraged. Still javac issues a
>> lint warning if it's absent:
>>
>>> "C:\Program Files\Java\jdk-15\bin\java.exe" --version
>> openjdk 15-ea 2020-09-15
>> OpenJDK Runtime Environment (build 15-ea+33-1546)
>> OpenJDK 64-Bit Server VM (build 15-ea+33-1546, mixed mode, sharing)
>>
>>> type Test.java
>> public record Test() implements java.io.Serializable {}
>>
>>> "C:\Program Files\Java\jdk-15\bin\javac.exe" --enable-preview --release=15
>>> -Xlint:all Test.java
>> Test.java:1: warning: [preview] records are a preview feature and may
>> be removed in a future release.
>> public record Test() implements java.io.Serializable {}
>>        ^
>> Test.java:1: warning: [serial] serializable class Test has no
>> definition of serialVersionUID
>> public record Test() implements java.io.Serializable {}
>>        ^
>> 2 warnings
>>
>> To my opinion, javac should be updated to skip this warning.
> yep, i agree.
>
>> With best regards,
>> Tagir Valeev.
> Rémi


More information about the amber-dev mailing list