Coming soon: serial lint warning enabled in the jdk build
Joe Darcy
joe.darcy at oracle.com
Fri Apr 4 00:52:17 UTC 2014
Hello,
Following up, the serial warning is now enabled in the jdk repo in the
dev forest:
8032977: Add serial lint warning to build of jdk repository
http://hg.openjdk.java.net/jdk9/dev/jdk/rev/a73632def406
Therefore the introduction of any new serializable class without a
serialVerionUID (or @SuppressWarning("serial") annotation) will not pass
the build.
Cheers,
-Joe
On 02/24/2014 10:55 AM, Joe Darcy wrote:
> Hello,
>
> In my JDK 9 development forest, I have a collection of changes that
> will resolve all the serial warnings in the jdk repo. [1] Over the
> next few weeks, these changes will go through review and integration.
> Once all the warnings are resolved, the serial lint warning will be
> enabled in the build. [2]
>
> Once that warning is enabled, all serializable classes must either
> declare a serialVersionUID or must have a @SuppressWarnings("serial")
> annotation.
>
> If a class has the usual long-term serialization contract, then it
> should declare a serialVersionUID. This is true both for classes that
> are part of Java SE (generally the java.* and javax.* namespaces) and
> classes that are marked as jdk.Exported(true) in the com.sun.* and
> jdk.* packages. If the class existed in JDK 8 or earlier, the
> serialVersionUID should match the result of the serialver computation
> in the earlier release. If the class is new in JDK 9, any value for
> the serialVersionUID can be used at the discretion of the maintainer
> of the class.
>
> If a class is serializable but does *not* have a long-term
> serialization contract, such as many swing classes, then the class
> should have a @SuppressWarnings("serial") annotation with a comment
> explaining why the warning should be suppressed. In the patches I've
> worked on explanation have included:
>
> * "Same-version serialization only" -- swing serial contract
> * "Superclass is not serializable across versions" -- subclass of a
> swing class
> * "JDK implementation class" -- e.g. a sun.* class or a
> jdk.Exported(false) class
> * "Anonymous class" -- anonymous classes and long-term serialization
> don't interact well
>
> In particular, since all exception types are serializable (thanks
> RMI!), new exception types introduced in JDK 9 must either have a
> serialVersionUID or a @SuppressWarnings("serial") annotation.
>
> Cheers,
>
> -Joe
>
> [1] JDK-8032976 Fix serial lint warnings in jdk libraries,
> https://bugs.openjdk.java.net/browse/JDK-8032976
>
> [2] JDK-8032977, Add serial lint warning to build of jdk repository,
> https://bugs.openjdk.java.net/browse/JDK-8032977
g
More information about the jdk9-dev
mailing list