[jikes-bugs] More about the sad state of affairs re serialVersionUID

Date view Thread view Subject view Author view

From: shieldsd@us.ibm.com
Date: Sat Feb 06 1999 - 14:19:52 EST


Picked up by dejanews .. yet another example of the difficulties
implemting a language without a specification ... dave

nberkman@my-dejanews.com wrote in message
<79clte$so1$1@nnrp1.dejanews.com>...
>
>Since I posted I've been in contact with the jikes team (who, by the way,
>is incredibly responsive!) They are trying to get more information from
>Sun about the algorithm used to generate serialVersionUID. I might as
>well ask here - does anyone know if this algorithm has been published?
>

Not only is the algorithm published, the source code for it is
given in the ObjectStreamClass.java and how it is called is
in the source code for ObjectInputStream and ObjectOutputStream.

It's almost surely not the algorithm, per se, that is the problem.
"The devil is in the details." Unfortunately, in order to get the
right serialVersionUID value, *EVERYTHING* in your computation
must be done the same way Sun does it.

Some of the most likely culprits (in increasing difficulty
of matching) are:
    Setting too MANY bits in the "access modifiers" int value.
    Setting too few bits therein.
    Not getting all the qualification modifiers the same as
        Sun's...even the modifiers that the compiler decides
        to toss in because it feels like it.
    Not putting in the static initializer method when Sun does.
    Putting in the static initializer method when Sun doesn't.
            (The static initializer method shows up in the
            list of methods as "<clinit>" ... kind of like a static
            constructor ... it's the toughest nut to crack correctly.)

Does this sound like I've done all this before? You betchum!

And I figured it all out by the simple expediency of putting
LOTS of System.out.println calls into the code that calculate
the serialVersionUID code. And running LOTS of classes
through the code on both the JDK and the VM we were
creating. And, every time I found a difference, going back
to the compiler writers and asking them to please fix the
blinking thing to match Sun. (Oh, okay, sometimes I
found ways to kludge a match myself.)

You are welcome to suggest to the Jikes people that
they should do the same thing. It only took me about
3 or 4 months to get it right to the point that even the
Swing components got the right values.

*******

IN THE MEANTIME...

An EASY fix for your problem is for YOU to assign
your own
        static final long serialVersionUID =
                0xFeedBeefDeadD0D0L; // or whatever

Honest, any random 64 bit number you choose
yourself has as much likelihood of accidentally matching
some other class as does the screwy calculation
that Sun uses! PLUS you have now made versioning
your class a WHOLE lot easier!

You can search DejaNews in this newsgroup for
my names and the topic "Serialization" to find
my numerous posts on this topic.

Bill Wilkinson

----
To get off the jikes-bugs list, send a message containing the word
"unsubscribe" (in the body, not the subject) to
<jikes-bugs-Request@Watson.IBM.Com>.

Send Majordomo commands to: <jikes-bugs-Request@Watson.IBM.Com> To contact a human: <jikes-bugs-Owner@Watson.IBM.Com> To post to the list: <jikes-bugs@Watson.IBM.Com>

----- End of forwarded message from shieldsd@us.ibm.com ----- ___________________________________________________________________________ Archie Cobbs * Whistle Communications, Inc. * http://www.whistle.com


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Sat Sep 23 2000 - 19:57:58 EDT