JDK-8160675 : Issue lint warning for non-serializable non-transient instance fields in serializable type
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-06-30
  • Updated: 2022-02-08
  • Resolved: 2021-10-21
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 18
18 b21Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
As an enhancement to javac's lint warnings about serialization (JDK-4767441), it would be informative if javac warned about the presence non-serializable non-transient instance fields in a serializable class. The types can lead to interesting instances of a type not being serializable in practice (JDK-6226715).

Such a warning should be omitted if a class defines serialPersistentFields (see https://docs.oracle.com/javase/8/docs/platform/serialization/spec/serial-arch.html#a5251).
Comments
Fold release note information for this issue into the release note for JDK-8202056.
08-02-2022

Changeset: 6a466fe7 Author: Joe Darcy <darcy@openjdk.org> Date: 2021-10-21 21:11:01 +0000 URL: https://git.openjdk.java.net/jdk/commit/6a466fe7ae281967d1cc4c8029b306f2d66567c9
21-10-2021

This is a fine goal, but it might be difficult in practice. Consider: class Foo<T> implements Serializable { List<T> someField = ... ; } The List interface isn't serializable, but convention is that most concrete List implementations in the JDK are serializable. And then of course there is the issue of whether the contents of the list can statically be determined to be serializable. You can't write class Foo<T extends Serializable> ... for the same reason, which is that T might not statically be a subtype of Serializable, while in practice instances of it might be. But maybe somebody else can see a way to do this that I can't.
19-04-2018