Bug 69942

Summary: compiler warning for serializable classes that do not explicitly declare serialVersionUID
Product: [Eclipse Project] JDT Reporter: Jim des Rivieres <jeem>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: akiezun, erich_gamma, John_Wiegand
Version: 3.0   
Target Milestone: 3.1 M1   
Hardware: All   
OS: All   
Whiteboard:

Description Jim des Rivieres CLA 2004-07-13 12:18:54 EDT
There should be a compiler warning for serializable classes that do not 
explicitly declare serialVersionUID. For maximum effectiveness, this compiler 
option should be "warning" by default.

ref: http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid

Serializable classes that do not declare serialVersionUID are a serious 
problem for people who build products that rely on Java serialization. The 
problem is that many people forget that changing their class will introduce 
compatibility problems with earlier releases of their product, and that the 
compiler's computation of a SUID is so fragile that it is not recommended.
In one case, only 50 of a product's 1500 serializable classes declared the 
SUID, making it difficult for them to provide inter-version compatibility.
Best practice dictates that one always declares serialVersionUID. (There are 
lots more things that need to be done to manage Java serializability, but this 
is a cornerstore of policy.)
Comment 1 Jim des Rivieres CLA 2004-07-13 14:27:57 EDT
*** Bug 69959 has been marked as a duplicate of this bug. ***
Comment 2 Philipe Mulet CLA 2004-07-14 09:52:35 EDT
*** Bug 67835 has been marked as a duplicate of this bug. ***
Comment 3 Philipe Mulet CLA 2004-07-20 12:55:07 EDT
Cannot implement for 3.0.1 since it would require to add a new API ID on 
IProblem (for quickfix).
Comment 4 Philipe Mulet CLA 2004-07-20 17:53:51 EDT
Added optional diagnosis, enabled as a warning by default as per request.
Added IProblem.MissingSerialVersion problem ID.
Comment 5 Philipe Mulet CLA 2004-07-20 18:13:13 EDT
New JavaCore option:

* COMPILER / Reporting Missing Declaration of serialVersionUID Field on 
Serializable Class
*    When enabled, the compiler will issue an error or a warning whenever a 
serializable class is missing a local declaration 
*    of a serialVersionUID field. This field must be declared as static final 
and be of type long.
*     - option 
id:         "org.eclipse.jdt.core.compiler.problem.missingSerialVersion"
*     - possible values:   { "error", "warning", "ignore" }
*     - default:           "warning"

Fixed.
Comment 6 Olivier Thomann CLA 2004-07-21 21:37:37 EDT
I updated the "howto" of the batch compiler usage.