Coming soon: serial lint warning enabled in the jdk build
Joe Darcy
joe.darcy at oracle.com
Mon Feb 24 10:55:12 PST 2014
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
More information about the jdk9-dev
mailing list