Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » serialVersionUID killing us
serialVersionUID killing us [message #281563] Mon, 21 February 2005 21:30 Go to next message
Eclipse UserFriend
Originally posted by: xixhub.na.direcway.com

I hate to harp on this, but I've done exactly as suggested. Jre1.5,
Eclipse3.1. and our big program dies as soon as the Data File, RN is
accessed. All of the classes that did any io had yellow warnings at the top
about UID's so I clicked on each one, selected the second option this time
as Olivier Thomann suggested in his anawer to my earlier posting.

Now as soon as the program tries to access RN data file we get:
Exception during deserialization: java.io.InvalidClassException:
org.charts.pkg.RN; local class incompatible: stream clasdesc
serialVersionUID = -914354........., local class serialVersionUID =
39058......11379

What now? I did research on all the Help functions, researched google, sun
micro systems, and of course none of the text's, even the bran new ones,
have anything to say about serialVersionUID, or what to do.

I'm at my wits end, and we are out of business!

Does anyone know how to tame this thing?
Re: serialVersionUID killing us [message #281567 is a reply to message #281563] Mon, 21 February 2005 22:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: olivier_thomannNOSPAM.ca.ibm.com

Sam King a écrit :
> Now as soon as the program tries to access RN data file we get:
> Exception during deserialization: java.io.InvalidClassException:
> org.charts.pkg.RN; local class incompatible: stream clasdesc
> serialVersionUID = -914354........., local class serialVersionUID =
> 39058......11379
It seems that you are trying to deserialize instances that have been
serialized before you added the serialVersionUID.
Could you please describe what you are doing exactly?
--
Olivier
Re: serialVersionUID killing us [message #281570 is a reply to message #281563] Mon, 21 February 2005 23:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

Sam King wrote:
> I hate to harp on this, but I've done exactly as suggested. Jre1.5,
> Eclipse3.1. and our big program dies as soon as the Data File, RN is
> accessed. All of the classes that did any io had yellow warnings at the top
> about UID's so I clicked on each one, selected the second option this time
> as Olivier Thomann suggested in his anawer to my earlier posting.
>
> Now as soon as the program tries to access RN data file we get:
> Exception during deserialization: java.io.InvalidClassException:
> org.charts.pkg.RN; local class incompatible: stream clasdesc
> serialVersionUID = -914354........., local class serialVersionUID =
> 39058......11379
>

well you could set your serialVersionUID to match the one in the stream
public static final long serialVersionUID = -914354...;

> What now? I did research on all the Help functions, researched google, sun
> micro systems, and of course none of the text's, even the bran new ones,
> have anything to say about serialVersionUID, or what to do.
>
> I'm at my wits end, and we are out of business!
>
> Does anyone know how to tame this thing?
>
>

SerialversionUID is untameable. That is why everyone recommends you
have one. Otherwise the compiler will generate one for you based on
properties of your file. If you change single thing(generally) you
will get a new serialversionUID, and your old files will no longer
deserialize. You can change someting totally unrelated to
deserilaization like a method name, and that will break your
deserialization of previously serialized classes because the UID will be
now different.

You must go back to the EXACT java/class files you had when you
serialized them. OR you must make your current UID match the old UID.



CL
Re: serialVersionUID killing us [message #281572 is a reply to message #281570] Mon, 21 February 2005 23:55 Go to previous messageGo to next message
Eclipse UserFriend
> You must go back to the EXACT java/class files you had when you serialized
> them. OR you must make your current UID match the old UID.

Hail to Eclipse's file history service!

But be carefull about that. Another option - beside dont use serialization
for the long term storage - is using customized readObject, writeObject
implementations. They are quite easy to implement and you can
versionize the format you are saving in. (storing an in before you read
something)

But I would rather go for XML anyways.


Bye,

Martin (Kersten)
Re: serialVersionUID killing us [message #281588 is a reply to message #281572] Tue, 22 February 2005 09:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aks.terma.com

we made a template for controlling this
// Turn off automatic generation of serialVersionUID

public static final long serialVersionUID = 1;

private static final int FORMAT_VERSION = 1;

public int getFormatVersion() {

return FORMAT_VERSION;

}

additionally, we implemented extrernalisable in order to control streaming
ourselves.

this way, we had our own format version to test on - if we want to support
streaming of different versions, we just stream the format version as well
and tests on this in readExternal, then decide the read mechanism.

If the streaming changes, jsut increment the format version

/aksel
Re: serialVersionUID killing us [message #281592 is a reply to message #281563] Tue, 22 February 2005 10:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.rizzoweb.com

Sam King wrote:
> I hate to harp on this, but I've done exactly as suggested. Jre1.5,
> Eclipse3.1. and our big program dies as soon as the Data File, RN is
> accessed. All of the classes that did any io had yellow warnings at the top
> about UID's so I clicked on each one, selected the second option this time
> as Olivier Thomann suggested in his anawer to my earlier posting.
>
> Now as soon as the program tries to access RN data file we get:
> Exception during deserialization: java.io.InvalidClassException:
> org.charts.pkg.RN; local class incompatible: stream clasdesc
> serialVersionUID = -914354........., local class serialVersionUID =
> 39058......11379
>
> What now? I did research on all the Help functions, researched google, sun
> micro systems, and of course none of the text's, even the bran new ones,
> have anything to say about serialVersionUID, or what to do.
>
> I'm at my wits end, and we are out of business!
>
> Does anyone know how to tame this thing?

Lots of other replies, but I wanted to point out some pages that explain
it in detail. I hope you understand that this is not an Eclipse problem
at all - you're just running into common issues with Java object
serialization. Anyway, read here:
http://java.sun.com/developer/technicalArticles/Programming/ serialization/

And here is a good explanation of the rule of thumb "Always Declare
Serial Version UID": http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid

HTH,
Eric
Re: serialVersionUID killing us [message #281597 is a reply to message #281563] Tue, 22 February 2005 11:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: grundig.wp.pl

Sam King wrote:

> I hate to harp on this, but I've done exactly as suggested. Jre1.5,
> Eclipse3.1. and our big program dies as soon as the Data File, RN is
> accessed. All of the classes that did any io had yellow warnings at the
> top about UID's so I clicked on each one, selected the second option this
> time as Olivier Thomann suggested in his anawer to my earlier posting.
>
> Now as soon as the program tries to access RN data file we get:
> Exception during deserialization: java.io.InvalidClassException:
> org.charts.pkg.RN; local class incompatible: stream clasdesc
> serialVersionUID = -914354........., local class serialVersionUID =
> 39058......11379
>
> What now? I did research on all the Help functions, researched google,
> sun micro systems, and of course none of the text's, even the bran new
> ones, have anything to say about serialVersionUID, or what to do.
>
> I'm at my wits end, and we are out of business!
>
> Does anyone know how to tame this thing?

Eclipse just warnings about potential programming problems. If you don't
care about it and know what are you doing you can just turn it off.
Window > Preferences > Java > Compiler > Errors/Warnings > Potential
programming problems > Serializable class without serialVersionUID

--
Pozdrawiam,
grundig
Re: serialVersionUID killing us [message #281638 is a reply to message #281588] Wed, 23 February 2005 08:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

Though its called serialVersionUID it is not about file storage. Its
about the version of the 'class' being serialized. changing a method
name is an indication that the class is not the same anymore, so to
create a class from it during serialization is wrong.

I think eclipse is wrong in stating that the lack of serialVersionUID is
worth a warning. In fact the presence of that number should be worth
a warning. Its an indicaiton that serialization is being used for 'long
term storage' in general. And 'long term' is not really time related.
just means to ROM or HD and not to RAM, IMHO.

you are correct to use your own storage method. Personally I still am
saving with serilization, but eventually I will not be.

CL



Aksel Schmidt wrote:
> we made a template for controlling this
> // Turn off automatic generation of serialVersionUID
>
> public static final long serialVersionUID = 1;
>
> private static final int FORMAT_VERSION = 1;
>
> public int getFormatVersion() {
>
> return FORMAT_VERSION;
>
> }
>
> additionally, we implemented extrernalisable in order to control streaming
> ourselves.
>
> this way, we had our own format version to test on - if we want to support
> streaming of different versions, we just stream the format version as well
> and tests on this in readExternal, then decide the read mechanism.
>
> If the streaming changes, jsut increment the format version
>
> /aksel
>
>
Re: serialVersionUID killing us [message #281645 is a reply to message #281638] Wed, 23 February 2005 10:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.rizzoweb.com

CL [dnoyeb] Gilbert wrote:
> Though its called serialVersionUID it is not about file storage. Its
> about the version of the 'class' being serialized. changing a method
> name is an indication that the class is not the same anymore, so to
> create a class from it during serialization is wrong.
>
> I think eclipse is wrong in stating that the lack of serialVersionUID is
> worth a warning. In fact the presence of that number should be worth a
> warning. Its an indicaiton that serialization is being used for 'long
> term storage' in general. And 'long term' is not really time related.
> just means to ROM or HD and not to RAM, IMHO.

That's not necessarily true. Serialization is often used to send objects
"over the wire" to other programs, which is not "long-term storage."
It is a pretty widely accepted "best practice" to always use explicit
serialVersionUID in Serializable classes. Yes, writing your own
serialization methods is useful, too - but for simple classes that isn't
worth the effort. See the links I provided in my post yesterday.

Eric
Re: serialVersionUID killing us [message #281654 is a reply to message #281638] Wed, 23 February 2005 12:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wegener.cboenospam.com

Maybe the warning should be on the use of the Serializable interface.

The purpose of the serialVersionUID is to indicate whether two different
instances of a class are compatible with respect to serialization, not to
indicate whether two different instances of a class are identical. If the
only change between the two instances of the class was a method name they
would be compatible with respect to serialization. Changing a field name
would break compatibility.

The serialized form of an object represents its state. Method names and
signatures are not part of the state of an object. Unfortunately, method
names are used by the serialization runtime to calculate a default
serialVersionUID. Inner classes require that method signatures be altered
and method names be generated by the compiler. The Java language spec
does not specify how the methods are altered or the names are changed.
This leaves it up to each compiler vendor. This makes the default
serialVersionUID that is calculated by the serialization runtime is
dependent on compiler implementations. The exact same Java code using the
exact same JDK release built with compilers from 2 different vendors will
produce class files that produce different default serialVersionUIDs.

Explicitly declaring a serialVersionUID solves the compiler discrepency
problem. However, it places an added burden on the developer to recognize
actual serializable differences between two versions of a given class. If
a field is different between, they aren't compatible. If the
serialVersionUID isn't changed as well, there will likely be problems.

Its kind of a damned if you do, damned if you don't situation. Flagging
the use of the Serializable interface would account for either situation.


CL [dnoyeb] Gilbert wrote:

> Though its called serialVersionUID it is not about file storage. Its
> about the version of the 'class' being serialized. changing a method
> name is an indication that the class is not the same anymore, so to
> create a class from it during serialization is wrong.

> I think eclipse is wrong in stating that the lack of serialVersionUID is
> worth a warning. In fact the presence of that number should be worth
> a warning. Its an indicaiton that serialization is being used for 'long
> term storage' in general. And 'long term' is not really time related.
> just means to ROM or HD and not to RAM, IMHO.

> you are correct to use your own storage method. Personally I still am
> saving with serilization, but eventually I will not be.

> CL



> Aksel Schmidt wrote:
>> we made a template for controlling this
>> // Turn off automatic generation of serialVersionUID
>>
>> public static final long serialVersionUID = 1;
>>
>> private static final int FORMAT_VERSION = 1;
>>
>> public int getFormatVersion() {
>>
>> return FORMAT_VERSION;
>>
>> }
>>
>> additionally, we implemented extrernalisable in order to control streaming
>> ourselves.
>>
>> this way, we had our own format version to test on - if we want to support
>> streaming of different versions, we just stream the format version as well
>> and tests on this in readExternal, then decide the read mechanism.
>>
>> If the streaming changes, jsut increment the format version
>>
>> /aksel
>>
>>
Re: serialVersionUID killing us [message #281770 is a reply to message #281645] Fri, 25 February 2005 11:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

Eric Rizzo wrote:
> CL [dnoyeb] Gilbert wrote:
>
>> Though its called serialVersionUID it is not about file storage. Its
>> about the version of the 'class' being serialized. changing a method
>> name is an indication that the class is not the same anymore, so to
>> create a class from it during serialization is wrong.
>>
>> I think eclipse is wrong in stating that the lack of serialVersionUID
>> is worth a warning. In fact the presence of that number should be
>> worth a warning. Its an indicaiton that serialization is being used
>> for 'long term storage' in general. And 'long term' is not really
>> time related. just means to ROM or HD and not to RAM, IMHO.
>
>
> That's not necessarily true. Serialization is often used to send objects
> "over the wire" to other programs, which is not "long-term storage."

This is what I said right?

> It is a pretty widely accepted "best practice" to always use explicit
> serialVersionUID in Serializable classes. Yes, writing your own
> serialization methods is useful, too - but for simple classes that isn't
> worth the effort. See the links I provided in my post yesterday.
>
> Eric

Even if it is widely accepted I feel its wrong. So far as I have
witnessed this widely accepted use is only related to data storage, not
transmission 'over the wire.' Most people when they change a class they
they are sending over the wire, they expect it to not be compatible.
Its only the storage people that expect a changed method name to remain
compatible.


CL
Re: serialVersionUID killing us [message #281776 is a reply to message #281654] Fri, 25 February 2005 11:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

David Wegener wrote:
> Maybe the warning should be on the use of the Serializable interface.
> The purpose of the serialVersionUID is to indicate whether two different
> instances of a class are compatible with respect to serialization, not
> to indicate whether two different instances of a class are identical. If
> the only change between the two instances of the class was a method name
> they would be compatible with respect to serialization. Changing a
> field name would break compatibility.

I don't think u are correct. Serialization is sending the 'class' over
the wire. This can be shortened by sending only the state if the
classes on both ends are equal. If I change a method of a class, the
class is NOT the same. serialVersionUID properly changes in this case to
indicate the difference.

> The serialized form of an object represents its state. Method names and
> signatures are not part of the state of an object. Unfortunately,
> method names are used by the serialization runtime to calculate a
> default serialVersionUID. Inner classes require that method signatures
> be altered and method names be generated by the compiler. The Java
> language spec does not specify how the methods are altered or the names
> are changed. This leaves it up to each compiler vendor. This makes the
> default serialVersionUID that is calculated by the serialization runtime
> is dependent on compiler implementations. The exact same Java code
> using the exact same JDK release built with compilers from 2 different
> vendors will produce class files that produce different default
> serialVersionUIDs.
>

Again, storage may be about state, but serialization is not. Consider
RMI and how it can ensure class file compatability under your scheme?
It could not. And different compilers should produce different SUIDs
because the class files may in fact be different.


> Explicitly declaring a serialVersionUID solves the compiler discrepency
> problem. However, it places an added burden on the developer to
> recognize actual serializable differences between two versions of a
> given class. If a field is different between, they aren't compatible.
> If the serialVersionUID isn't changed as well, there will likely be
> problems.
> Its kind of a damned if you do, damned if you don't situation. Flagging
> the use of the Serializable interface would account for either situation.
>

What I am suggesting is that if someone has a SUID in their file they
are probably using serialization for long term storage, would you agree?
And if they are, that deserves a warning as this is not what
serialization is for. Thats really my whole point. But what we have
today is the opposite, you get a warning when you don't have a SUID.
But why should you? If you are marshalling you classes, its easier to
have the compiler verify that your class signature has not changed, than
for you to keep track yourself.



CL
Re: serialVersionUID killing us [message #281780 is a reply to message #281776] Fri, 25 February 2005 12:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bob.objfac.com

CL [dnoyeb] Gilbert wrote:
> I don't think u are correct. Serialization is sending the 'class' over
> the wire. This can be shortened by sending only the state if the
> classes on both ends are equal. If I change a method of a class, the
> class is NOT the same. serialVersionUID properly changes in this case to
> indicate the difference.

Yes, yes. You've said that several times. There are two points to be made:

1) When the class changes incompatibly, of course the serialVersionUID
must change.

2) It is not a good idea to leave setting the serialVersionUID to the
compiler, as that makes it compiler-specific. Unless you can ensure that
you will always compile the class with the same compiler and the
compiler won't change the way it computes serialVersionUID, you don't
want that.

Therefore, the best practice is to set the UID by hand and change it
when you need to, by hand. Too bad, but that's the way it is.

Bob Foster
Re: serialVersionUID killing us [message #281784 is a reply to message #281780] Fri, 25 February 2005 13:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Lamont_Gilbert.rigidsoftware.com

Bob Foster wrote:
> CL [dnoyeb] Gilbert wrote:
>
>> I don't think u are correct. Serialization is sending the 'class'
>> over the wire. This can be shortened by sending only the state if the
>> classes on both ends are equal. If I change a method of a class, the
>> class is NOT the same. serialVersionUID properly changes in this case
>> to indicate the difference.
>
>
> Yes, yes. You've said that several times. There are two points to be made:
>
> 1) When the class changes incompatibly, of course the serialVersionUID
> must change.
>
> 2) It is not a good idea to leave setting the serialVersionUID to the
> compiler, as that makes it compiler-specific. Unless you can ensure that
> you will always compile the class with the same compiler and the
> compiler won't change the way it computes serialVersionUID, you don't
> want that.
>
> Therefore, the best practice is to set the UID by hand and change it
> when you need to, by hand. Too bad, but that's the way it is.
>

You may want to set the UID, but I wouldn't call it 'best practice.'
Its optional. If you set it, you have a set of issues to deal with. If
you do not set it, that entails its own set of issues.

CL
Re: serialVersionUID killing us [message #281788 is a reply to message #281780] Fri, 25 February 2005 13:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: olivier_thomannNOSPAM.ca.ibm.com

Bob Foster a écrit :
> 2) It is not a good idea to leave setting the serialVersionUID to the
> compiler, as that makes it compiler-specific. Unless you can ensure that
> you will always compile the class with the same compiler and the
> compiler won't change the way it computes serialVersionUID, you don't
> want that.
Just to clarify. The compiler doesn't do the computation. It is done at
runtime, but it is compiler-specific, because the default serialization
is using the synthetic methods added by the compiler in its computation
of a runtime serialVersionUID.
Keeping the same compiler means same version. For example, there is no
garantee that javac 1.4 and javac 1.5 would produce the same
serialVersionUID at runtime. If you use class literal (A.class) in your
code, it won't.
> Therefore, the best practice is to set the UID by hand and change it
> when you need to, by hand. Too bad, but that's the way it is.
yes, it is recommended by Sun to set a serialVersionUID.
--
Olivier
Re: serialVersionUID killing us [message #284515 is a reply to message #281788] Tue, 26 April 2005 21:31 Go to previous messageGo to next message
Eclipse UserFriend
I've just been lurking on this serialVersionUID thread (just installed
Eclipse 3.1 and saw the warning for the first time) but thanks to
everyone for giving their time to such a fascinating discussion...I have
learned a lot just from reading it critically, and it is good to know
there are such knowledgeable people as yourselves...maybe I can be one
someday. -- Alan Canon
Re: serialVersionUID killing us [message #284523 is a reply to message #284515] Wed, 27 April 2005 02:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: antoni.alatalo.kolumbus.fi

Alan Canon wrote:
> I've just been lurking on this serialVersionUID thread (just installed
> Eclipse 3.1 and saw the warning for the first time) but thanks to
> everyone for giving their time to such a fascinating discussion...I have
> learned a lot just from reading it critically, and it is good to know
> there are such knowledgeable people as yourselves...maybe I can be one
> someday. -- Alan Canon
Hi,
can you tell in what newsgroup this was discussed?

Thanks

Antoni
Re: serialVersionUID killing us [message #284712 is a reply to message #281654] Fri, 29 April 2005 00:32 Go to previous message
Eclipse UserFriend
David Wegener wrote:

> Maybe the warning should be on the use of the Serializable interface.

No. JavaBeans must be serializable. I don't know why though :)
Previous Topic:Problem with text files encoding recognition
Next Topic:Eclipse Help Problem
Goto Forum:
  


Current Time: Fri Oct 31 10:27:03 EDT 2025

Powered by FUDForum. Page generated in 0.27065 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top