classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: serialVersionUID


From: Dalibor Topic
Subject: Re: serialVersionUID
Date: Thu, 26 Sep 2002 04:34:18 -0700 (PDT)

Hi Giannis,
--- Giannis Georgalis <address@hidden> wrote:
> Eric Blake <address@hidden> writes:
> 
> > It is necessary for serialization, although it is
> usually a private
> > field. ALL classes in classpath which implement
> java.io.Serializable
> > should declare this field, and it should match the
> results of running
> > Sun's serialver tool on that class; otherwise,
> Classpath will not be
> > compatible for serialization. 
> java.io.ObjectStream uses the value of
> > this field to see if two class versions are
> compatible. This field is
> > needed in Classpath even when Sun's jar does not
> have the
> > field. (Interfaces which extend Serializable do
> not need this field).
> 
> Thank you Eric, I however had to run the serialver
> tool on a
> i386/solaris8 system (I didn't want to install sun's
> SDK on my
> computer, just for the serialver tool). Does the
> output match
> every system ? Is there a posibility that there are
> different
> serialVersionUIDs for different systems?

Just having the serialVersionUID right does not mean
that the serialized versions are compatible. It is
like a checksum over a class definition. Since
classpath implementation of most classes should be
significantly different from sun,s, it is necessary to
fake it if you want to be able to exchange serialized
forms between different implementations. But just
faking the checksum does not magically create
interoperability. The approach used in kaffe is to use
incompatible serialVersionUIDs for classes where there
is no copatibility layer yet, to avoid confusion about
apparently right checksums, but incompatible
serialized forms.

Having the serialVersionUID encoded in the class is
just a performance gain during serialization.
Otherwise it would have to be calculated just in time
for serialization, using reflection, for example. I
assume that is what classpath does for serializable
classes without a serialVersionUID.

If classpath uses different implementations of java
classes on different platforms the genuine
serialVersionUID for the different implementations
will obviously differ. I assume that Suns
serialVersionUID is the same on all platforms, though;
otherwise one could not reliably exchange serialized
forms over networks, for example. I dont think Sun has
specified serialVersionUIDs in the API, though, so you
may have to dig around the API specs, or use serialver
on Suns implementation, if you want to be compatible
with them.

best regards,

dalibor topic

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com




reply via email to

[Prev in Thread] Current Thread [Next in Thread]