JDK-8202385 : Annotation to mark serial-related fields and methods
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 11
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-04-27
  • Updated: 2021-01-10
  • Resolved: 2019-08-20
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 14
14 b11Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
The serialization related fields (serialVersionUID and serialPersistentFields) and methods (writeObject, writeReplace, readObject,  readObjectNoData, readResolve), have names that are possible to misspell. The serialization mechanism will silently ignore misspelled (or otherwise misdeclared) fields and methods.

Similar to how the java.lang.Override annotation type is used to signal the compiler should verify the method is in fact overridden, it would be helpful to some kind of "SerialRelated" annotation to facilitate automated checking of the declarations of serial fields and methods.
Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/0abdc5a425dd User: darcy Date: 2019-08-20 01:12:25 +0000
20-08-2019

Given the other serial-related types are in the java.io package, that is a reasonable place for such an annotation to live as well. The possible methods and fields to be checked are, first, five methods: private void writeObject(java.io.ObjectOutputStream stream) throws IOException; private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException; private void readObjectNoData() throws ObjectStreamException ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException; ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException; and two fields: private static final ObjectStreamField[] serialPersistentFields; private static final long serialVersionUID; Note the concern raised about "covariant overrides" causing a readResolve method to be ineffectual, JDK-6714327.
16-07-2019

Out for review: http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-May/053055.html Initial reviews by rriggs and alanb; additional comments from David Lloyd. Additional review thread: http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-August/054801.html And another: http://mail.openjdk.java.net/pipermail/core-libs-dev/2019-July/061247.html
09-07-2019

Straw-man annotation type: @Target({ElementType.METHOD, ElementType.FIELD}) @Retention(RetentionPolicy.SOURCE) public @interface SerialRelated{ } A source retention is consist with Override and SuppressWarnings; a runtime retention would allow core reflection based checkers too.
27-04-2018