Bug 39317 - SerialVersionUID generated by Eclipse is different than by JDK/javac
Summary: SerialVersionUID generated by Eclipse is different than by JDK/javac
Status: RESOLVED DUPLICATE of bug 10104
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC All
: P3 major (vote)
Target Milestone: 3.0 M2   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-06-25 08:39 EDT by edwin steiner CLA
Modified: 2003-06-25 11:21 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***