Classes generated by eclipse vs javac have different serialVersionUID

Discussion in 'Java' started by tai.thach@gmail.com, Jul 27, 2006.

  1. Guest

    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
    , Jul 27, 2006
    #1
    1. Advertising

  2. Paul Davis Guest

    wrote:
    > 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.
    Paul Davis, Jul 27, 2006
    #2
    1. Advertising

  3. Guest

    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


    Paul Davis wrote:
    > wrote:
    > > 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.
    , Jul 27, 2006
    #3
  4. Paul Davis Guest

    wrote:
    > 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
    >
    >
    > Paul Davis wrote:
    > > wrote:
    > > > 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.


    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
    Paul Davis, Jul 28, 2006
    #4
  5. wrote in news:1154024384.502849.220290
    @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

    A. Top posters.
    Q. What is the most annoying thing on Usenet?
    ---------------------------------------------------------------------
    Greg R. Broderick, Jul 28, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven

    serialVersionUID and Eclipse

    Steven, Apr 29, 2005, in forum: Java
    Replies:
    1
    Views:
    778
    Peter MacMillan
    Apr 29, 2005
  2. Markus

    serialVersionUID in Eclipse

    Markus, Jul 20, 2005, in forum: Java
    Replies:
    2
    Views:
    6,077
    Markus
    Jul 21, 2005
  3. Sameer
    Replies:
    19
    Views:
    58,281
    Oliver Wong
    Sep 15, 2005
  4. Jimmy
    Replies:
    7
    Views:
    11,482
    Esmond Pitt
    Aug 1, 2007
  5. lightning
    Replies:
    1
    Views:
    355
    Owen Jacobson
    Sep 16, 2008
Loading...

Share This Page