(Answer) (Category) FAQ-O-Matic : (Category) General : (Category) Compiler : (Category) Javac VS JBuilder's bcj :
The serialVersionUID from classes compiled by JB4 doesn't match Sun's javac 1.3 or 1.4.
A recent change in Sun's javac has created a new incompatiblity between class files compiled by it and by JBuilder's compiler.

Inner classes gain access to their container class variables using auto-generated access methods created by the compiler as needed. The specification declares that these methods should be named "access$n" and this is the form javac 1.2.2 (and earlier) and other compilers have used (including JBuilder's).

The problem appears in javac 1.3 and 1.4, which has changed the name of the access methods to "access$nnn" meaning the number appended to the name now contains leading zeroes.

Because the serialVersionUID is computed using the method names within the class, the change in the access methods changes the computed value. So, the same class file compiled by javac 1.2.2 and 1.3 will have different values! Of course, this applies to JBuilder's compiler, also.

The only way to get around this problem is to ensure all copies of your class files were compiled by the same compiler, or by compilers known to produce compatible method names.

The DUMMY static constant trick mentioned elsewhere will not fix this problem, only recompiling with a compatible compiler will do it.
2001-Jun-02 11:57am gyles19@visi.com

See also:

(Xref) Should the "Include debug info" switch affect the serialVersionUID?
2001-Jul-09 2:28pm gyles19@visi.com

John McGrath [TeamB] writes:

I have not looked at this for a while, and I see that Borland has changed the compiler to always generate the static initializer block, regardless of whether the -g option is used.

It seems as if Java compiler developers have been grappling with this issue, as different versions of compilers handle this differently. I compiled the following program with various compilers, both with and without the debug (-g) option.

    public class SUID implements java.io.Serializable {
        public static final String suid = "suid";
    }

As you can see, the results are somewhat mixed.

                   Debug (-g)
                   ----------
    Compiler       Yes     No
                   ---     --
    JDK 1.1.8       N       N
    JDK 1.2.2       N       N
    JDK 1.3         N       N
    JDK 1.3.1       N       N
    JDK 1.4         N       Y
    Jikes 1.12      N       N
    Kaffe 1.4F      Y       Y
    JBuilder 4      N       Y
    JBuilder 5      Y       Y
    JBuilder 6      Y       Y
N = Does not have static initializer SerialVersionUID = 2823290551686321412L;
Y = Has static initializer SerialVersionUID = -2815904881746903822L;

I am going to see if I can find out more about this.

I presume that the reason you are concerned about this is that the default SerialVersionUID varies depending on the compiler. The way to fix that is to add a static non-final variable with an initializer into your class. Then, you will have a static initializer with all compilers and there will be no compatibility issues. For example:

   private static int DUMMY = 1;

2002-Mar-03 2:08pm gyles19@visi.com
Another source of serialVersionUID mismatch is the use of rmiregistry in a JVM outside of the JVM that's running the application. You must address the 'rmi codebase' issues and/or call java.rmi.registry.LocateRegistry.createRegistry() within your application.


2002-Apr-17 6:02am gyles19@visi.com

[Append to This Answer]
2002-Apr-17 6:02am
Previous: (Answer) Usage of this$0
Next: (Answer) super.getSuperclass() and getClass.getSuperclass() return different results! Code compiled with javac returns the same value, but code compiled with JBuilder does not!
This document is: http://www.visi.com/~gyles19/cgi-bin/fom.cgi?file=185
[Search] [Appearance]
This is a Faq-O-Matic 2.709.
This FAQ administered by gyles19@visi.com.

Other JBuilder Links

Java Community
Java Tools
Code Central
JB OpenTools
Community
Recent
Threads
Borland Chat
Chat FAQ
Feature Matrices
3.0 |  3.5 |  4.0
5.0 |  6.0 |  7.0
Shop for
JBuilder
JBuilder
Downloads
and reg keys
Report Piracy
Online Manuals
4.0 |  5.0 |  6.0
7.0
Borland
DevSupport's
Bug/RFE Form

Quality Central Client
JB Patches &
Updates
JBuilder FAQs TIs
JBuilder
Newsgroups
Tamaracka's
News Archive
Mr. Haki's
JBuilder Machine
JGuru's
JBuilder FAQ
Sun's Bug
Parade
Netring Home - About - Privacy
The
JBuilder Netring Logo
The Borland JBuilder Netring by JBuilder FAQ-O-Matic
[ Join Now | List Sites | Random | << Prev | Next >> ]
[ Previous 5 Sites | Skip Previous | Skip Next | Next 5 Sites ]