[records] Is serialVersionUID warning for records redundant?

B. Blaser bsrbnd at gmail.com
Thu Sep 24 09:34:42 UTC 2020


[CC to compiler-dev]

Hi,

I'd like to suggest the following straightforward fix to suppress the
serial lint warning for records (based on jdk14u), any feedback is
welcome! Then, if you need it quickly, feel free to push it on my
behalf at the right place since I'm currently not up-to-date with the
new git work-flow (or maybe add it to JDK-8246774 [1]).

Thanks,
Bernard

[1] https://git.openjdk.java.net/jdk/pull/290.diff

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;
             }

> From: chris.hegarty at oracle.com (Chris Hegarty)
> Date: Tue, 4 Aug 2020 08:48:36 +0100
>
>> On 3 Aug 2020, at 08:30, Tagir Valeev <amaembo at gmail.com> wrote:
>>
>> 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:
>
> Yeah, this is a bug. We already have an issue in JIRA tracking this:
>
> 8241151: "Incorrect lint warning for no definition of serialVersionUID in a record? [1]
>
> -Chris
>
> [1] https://bugs.openjdk.java.net/browse/JDK-8241151


More information about the compiler-dev mailing list