Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / July 2006

Tip: Looking for answers? Try searching our database.

Classes generated by eclipse vs javac have different serialVersionUID

Thread view: 
tai.thach@gmail.com - 27 Jul 2006 19:12 GMT
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
Oliver Wong - 28 Jul 2006 15:23 GMT
> Hi,
> I'm using eclipse 3.2 for development and have configured my project to
[quoted text clipped - 19 lines]
> scouring the web to find a solution, but have had no success. Any help
> would be really appreciated!

   Isn't it possible to directly specify the serialversionUID by declaring
the appropriate static field?

   - Oliver
tai.thach@gmail.com - 28 Jul 2006 17:58 GMT
It is possible to specify the serialVersionUID, however, if I do that I
have to make sure that it is exactly the same as the original class
file. Although I can find the old class file and get its
serialVersionUID, I am betting that there is no other version out there
that may have had a different UID. I think this is a fairly safe bet,
but as this is a product that has shipped to numerous customers, I
cannot make this change without handling all the different scenarios.
This would involve much more code and testing, which is not currently
possible for me.

> > Hi,
> > I'm using eclipse 3.2 for development and have configured my project to
[quoted text clipped - 24 lines]
>
>     - Oliver
Oliver Wong - 28 Jul 2006 19:42 GMT
[post re-ordered]

>> > Hi,
>> > I'm using eclipse 3.2 for development and have configured my project to
[quoted text clipped - 33 lines]
> This would involve much more code and testing, which is not currently
> possible for me.

   From the JavaDocs:
http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html
<quote>
it is strongly recommended that all serializable classes explicitly declare
serialVersionUID values, since the default serialVersionUID computation is
highly sensitive to class details that may vary depending on compiler
implementations, and can thus result in unexpected InvalidClassExceptions
during deserialization. Therefore, to guarantee a consistent
serialVersionUID value across different java compiler implementations, a
serializable class must declare an explicit serialVersionUID value.
</quote>

   Also, AFAIK, the Java serialization mechanism is not intended for long
term storage of objects, so if you need to serialize and deserialize objects
across different versions of your application, you may be in for a lot of
headaches.

   I'm not sure that there's a quick fix for this problem. You may have to
do some re-design work.

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.