Bug 32227

Summary: Serialization incompatibility with Sun's 1.4 compiler
Product: [Eclipse Project] JDT Reporter: Stephen Summerfield <stephen>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3    
Version: 2.0.1   
Target Milestone: 2.1 RC1   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Stephen Summerfield CLA 2003-02-19 07:59:05 EST
Problem is that Eclipse compiler creates incompatible classes in terms of 
serialization with Sun's JDK1.4(.0) compiler.

Problem is demonstrated in a simple test program:

import java.io.Serializable;
public class Test implements Serializable
{
    public static String cName = Test.class.getName();
}

Running serialver on classes generated by Eclipse and Sun's JDK (both set to be 
1.4) from the same source file  gives:

Eclipse: Test:    static final long serialVersionUID = 1400023213535622423L;
Sun    : Test:    static final long serialVersionUID = 2953822734317990598L;

Also causes problems debugging client/server programs (that use serialization).

If the line in the above program is changed to be:

    public static String cName = "Test";

both classes then have the same serialVersionUID.
Comment 1 Philipe Mulet CLA 2003-02-19 08:25:12 EST
Serialization is sensitive to compiler synthetic emulation, which is spec'ed 
nowhere in the JLS. This is unfortunate, and until the JLS covers it, nobody is 
either wrong or right on this front. Eclipse compiler and javac perform 
differently on unspecified behavior.

There is nothing we can do to improve this, matching a particular version of 
javac would not be acceptable (reciprocally one could argue they should match 
us).

In general, one should *always* serialize/deserialize against binaries 
generated by the exact same compiler (and even against a particular compiler 
version). Alternatively, serialization should ignore synthetics (AccSynthetic 
is a modifier used to tag all exotic additions to classfile which can break 
serialization). The JLS/serialization has been aware of this weakness for 
years, and never decided to resolve it.

Comment 2 Philipe Mulet CLA 2003-02-19 08:27:07 EST

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