Bug 39317

Summary: SerialVersionUID generated by Eclipse is different than by JDK/javac
Product: [Eclipse Project] JDT Reporter: edwin steiner <edwin.steiner>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: major    
Priority: P3    
Version: 2.1   
Target Milestone: 3.0 M2   
Hardware: PC   
OS: All   
Whiteboard:

Description edwin steiner CLA 2003-06-25 08:39:59 EDT
The SerialVersionUID generated by Eclipse is different than the one generated by
JDK/javac in the case that the implementation uses a statement like '<class>.class'.

The following class returns for both compilers the SAME SerialVersionUID
(serialVersionUID = 4519452335893988861L;):
----------------------------------------------
import java.io.Serializable;
public class SerialVerTest implements Serializable {
    public void clazz() {
        Class c = new Object().getClass();
	//Class c = Object.class;
    }
}
----------------------------------------------

The following class returns DIFFERENT SerialVersionUIDs:
----------------------------------------------
import java.io.Serializable;
public class SerialVerTest implements Serializable {
    public void clazz() {
        //Class c = new Object().getClass();
	Class c = Object.class;
    }
}
----------------------------------------------
Eclipse compiler: serialVersionUID = 8816314731772278735L;
javac:            serialVersionUID = 8126007417160031246L;

Why are the SerialVersionUIDs different between the two implementations even
with the same compiler?


P.S.
java -version
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
Comment 1 Olivier Thomann CLA 2003-06-25 09:39:07 EDT
This is normal. Javac generates an extra method to handle the class literal
(.class syntax) and the Eclipse compiler doesn't do that. This extra method has
a side-effect on the serialVersionUID.
This is a known issue between compiler and cannot be fixed. The proper way is to
set the serialVersionUID inside the classes that you want to serialize. You can
get the same problem between different versions of the same compiler.
I will try to find the link that points to this issue on the Sun web site.
I would close as WONTFIX.
Comment 2 Olivier Thomann CLA 2003-06-25 09:54:25 EDT
Here is the link. It clearly states that the serialVersionUID should be set
http://java.sun.com/j2se/1.3/docs/guide/serialization/spec/class.doc6.html when
a class is using inner classes. In your case, it is similar. The class literal
code generation generates a new method if you use javac. You can see it by
disassembling the resulting .class file.
Comment 3 Philipe Mulet CLA 2003-06-25 11:21:07 EDT

*** This bug has been marked as a duplicate of 10104 ***