Community
Participate
Working Groups
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)
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.
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.
*** This bug has been marked as a duplicate of 10104 ***