wood burning stoves 2.0*
The moose likes Java in General and the fly likes Error in serialization java.io.InvalidClassException: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Error in serialization java.io.InvalidClassException: " Watch "Error in serialization java.io.InvalidClassException: " New topic
Author

Error in serialization java.io.InvalidClassException:

Stanley Walker
Ranch Hand

Joined: Sep 23, 2009
Posts: 87
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.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
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.
Santhosh ayiappan
Ranch Hand

Joined: Jan 30, 2007
Posts: 80

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

Joined: Sep 23, 2009
Posts: 87
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?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Jan 30, 2007
Posts: 80

You might need to verify whether you are using the right jar to load the modified class file.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error in serialization java.io.InvalidClassException: