Classes generated by eclipse vs javac have different serialVersionUID

T

tai.thach

Hi,
I'm using eclipse 3.2 for development and have configured my project to

use JDK 1.5.0_07 with Compiler compliance level 1.3 (using default
compliance settings) and selected all "Classfile Generation" options
except "Inline finally blocks." The problem I'm having is that the
class files that are generated by eclipse are not the same as those
generated by javac (also using JDK 1.5.0_07), which is used in a make
script. javac is invoked like so:

javac -source 1.3 -g -d classes -nowarn -deprecation -classpath
<classpath> ...


The different class files cause a problem because I have serialized
some objects already with the javac classes so when I try to
deserialize them with the eclipse classes, I get the
InvalidClassException. When I run serialver on the offending class
file, I get two different values for the class file generated with
javac and the one generated using eclipse.


Has anyone ever had this or some similar problem? How do I correct this

(besides not using the eclipse class files)? I've spent many hours
scouring the web to find a solution, but have had no success. Any help
would be really appreciated!
Thanks,
Tai
 
P

Paul Davis

Hi,
I'm using eclipse 3.2 for development and have configured my project to

use JDK 1.5.0_07 with Compiler compliance level 1.3 (using default
compliance settings) and selected all "Classfile Generation" options
except "Inline finally blocks." The problem I'm having is that the
class files that are generated by eclipse are not the same as those
generated by javac (also using JDK 1.5.0_07), which is used in a make
script. javac is invoked like so:

javac -source 1.3 -g -d classes -nowarn -deprecation -classpath
<classpath> ...


The different class files cause a problem because I have serialized
some objects already with the javac classes so when I try to
deserialize them with the eclipse classes, I get the
InvalidClassException. When I run serialver on the offending class
file, I get two different values for the class file generated with
javac and the one generated using eclipse.


Has anyone ever had this or some similar problem? How do I correct this

(besides not using the eclipse class files)? I've spent many hours
scouring the web to find a solution, but have had no success. Any help
would be really appreciated!
Thanks,
Tai

Tai,
Try defining this in your class:
private static final long serialVersionUID = 1L;
replace 1 with something sufficiently unique. Reserialize your data
afterwards as well. You should change the serial number when you change
your classes.
 
T

tai.thach

Hi Paul,
Thanks for your input. Unfortunately, this is not a feasible solution
for me because the application I'm working on has been deployed at
numerous clients already. So I cannot just add the serialVersionUID
field and regenerate all the classes because I would have to require
all the clients to also reserialize. As you might expect, no one wants
to have to do this. Plus, the data is already stored in those
previously serialized objects, so I still have to retrieve that data
before I could serialize it again with my new class. I've also
considered just using the serialVersionUID from the javac generated
class. But that assumes that the serialVersionUID generated on my
machine matches exactly what has been generated in the older versions
of the class (which did not have the serialVersionUID field). I'm not
completely confident that that assumption is always true.

Any other ideas?
Tai
 
P

Paul Davis

Hi Paul,
Thanks for your input. Unfortunately, this is not a feasible solution
for me because the application I'm working on has been deployed at
numerous clients already. So I cannot just add the serialVersionUID
field and regenerate all the classes because I would have to require
all the clients to also reserialize. As you might expect, no one wants
to have to do this. Plus, the data is already stored in those
previously serialized objects, so I still have to retrieve that data
before I could serialize it again with my new class. I've also
considered just using the serialVersionUID from the javac generated
class. But that assumes that the serialVersionUID generated on my
machine matches exactly what has been generated in the older versions
of the class (which did not have the serialVersionUID field). I'm not
completely confident that that assumption is always true.

Any other ideas?
Tai

Use the serialver program. Its in the bin directory of your JDK
install.
Point it to an original copy.
You should feed it the same classpath as the original was built on. Set
the new classes to use the value returned.
Hope that helps
 
G

Greg R. Broderick

(e-mail address removed) wrote in @p79g2000cwp.googlegroups.com:
Hi,
I'm using eclipse 3.2 for development and have configured my project to

use JDK 1.5.0_07 with Compiler compliance level 1.3 (using default
compliance settings) and selected all "Classfile Generation" options
except "Inline finally blocks." The problem I'm having is that the
class files that are generated by eclipse are not the same as those
generated by javac (also using JDK 1.5.0_07), which is used in a make
script. javac is invoked like so:

javac -source 1.3 -g -d classes -nowarn -deprecation -classpath
<classpath> ...


The different class files cause a problem because I have serialized
some objects already with the javac classes so when I try to
deserialize them with the eclipse classes, I get the
InvalidClassException. When I run serialver on the offending class
file, I get two different values for the class file generated with
javac and the one generated using eclipse.


Has anyone ever had this or some similar problem? How do I correct this

How about explicitly specifying the serialVersionUID in the serializable
classes? :)

c.f.
<http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/version.html>
<http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/class.html#
4100>


--
---------------------------------------------------------------------
Greg R. Broderick (e-mail address removed)

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top