• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Error in serialization java.io.InvalidClassException:

 
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I recently came across this error and was dumbstruck by it.
I am posting the statck trace. The error was resolved by setting serialVersionUID to some default value, however i am still unsure about why the error arose and its actual best solution.

] Exception in method deserializeStream [[
java.io.InvalidClassException: com.org.object.SomeDataClass; local class incompatible: stream classdesc serialVersionUID = 6017853943264163411, local class serialVersionUID = -1236842957120113434
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:562)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1583)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at java.util.HashMap.readObject(HashMap.java:1223)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at com.ofss.fc.infra.stream.StreamHelper.deserializeStream(StreamHelper.java:61)


the exception was seen while calling an application server from another web server, i.e from UI hosted in a web server to middleware services hosted in another application server.

Please help, this was a new exception to me and i would really appreciate any guidelines.
 
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi i came across this error when i serialized classes while using a JMS Service. This error occurred at the time when the class version known to the client was different from the server.

Can you check if the application where it is getting serialized & the application where it is getting deserialized has the same version of the class that implements serializable? Please check if you have modified the class code once after you have deployed in the server. Even a slight change to the serializable class will give this error.
 
Ranch Hand
Posts: 81
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would be getting the error if you had added any new fields or removed any fields from the class. You need to verify all the attributes of the class closely.

Regards
Santhosh
 
Stanley Walker
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you everyone for your replies.

John, the issue is that i am not explicitly serializing or deserializing the class any where explicitly. We use JSON for RPC calls and my guess is that the serialization happens at network behind the scenes. The class was altered but the latest class was compiled and deployed at both ends.


Santosh, my question is in case i do change the class it was recompiled and deployed at both UI and host end. still why is this issue arising?
 
Sheriff
Posts: 28414
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stanley Walker wrote:Santosh, my question is in case i do change the class it was recompiled and deployed at both UI and host end. still why is this issue arising?



That's a good question. The error message says that the class at the sending end is different than the class at the receiving end, so perhaps your procedure for synchronizing the classes in those two places doesn't work as well as you thought it did.
 
Santhosh ayiappan
Ranch Hand
Posts: 81
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might need to verify whether you are using the right jar to load the modified class file.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stanley Walker wrote: The error was resolved by setting serialVersionUID to some default value, however i am still unsure about why the error arose and its actual best solution.


that is why if you miss to add serialVersionUID the IDE like eclipse warns you. the reason is sender's serialized file and receiver's .class file might be different! or receiver's one of the .class/serialization file older than others. so try to take new version of serialization file and .class from sender.
reply
    Bookmark Topic Watch Topic
  • New Topic