Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

InvalidClassException while Retrieving the serialized object  RSS feed

 
glad guy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We write the Java Object in to DB (as BLOB data) and while Retrieving the object, we get the following error. It happens with some objects and not with all objects. . Any Idea?

java.io.InvalidClassException: com.project.test.org.Myclass$1; local class incompatible: stream classdesc serialVersionUID = -8944606277067230600, local class serialVersionUID = 2627933811729477083
at java.io.ObjectStreamClass.initNonProxy(Ljava.io.ObjectStreamClass;Ljava.lang.Class;Ljava.lang.ClassNotFoundException;Ljava.io.ObjectStreamClass V(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Z)Ljava.io.ObjectStreamClass;(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Z)Ljava.io.ObjectStreamClass;(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Unknown Source)
at java.io.ObjectInputStream.readObject0(Z)Ljava.lang.Object;(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.io.ObjectStreamClass V(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.ObjectStreamClass V(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Unknown Source)
at java.io.ObjectInputStream.readObject0(Z)Ljava.lang.Object;(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.io.ObjectStreamClass V(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.ObjectStreamClass V(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Unknown Source)
at java.io.ObjectInputStream.readObject0(Z)Ljava.lang.Object;(Unknown Source)
at java.io.ObjectInputStream.readObject()Ljava.lang.Object;(Unknown Source)
at java.util.HashMap.readObject(Ljava.io.ObjectInputStream V(Unknown Source)
at java.lang.LangAccessImpl.readObject(Ljava.lang.Class;Ljava.lang.Object;Ljava.io.ObjectInputStream V(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Ljava.lang.Object;Ljava.io.ObjectInputStream V(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.ObjectStreamClass V(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Unknown Source)
at java.io.ObjectInputStream.readObject0(Z)Ljava.lang.Object;(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Ljava.lang.Object;Ljava.io.ObjectStreamClass V(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.ObjectStreamClass V(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Unknown Source)
at java.io.ObjectInputStream.readObject0(Z)Ljava.lang.Object;(Unknown Source)
at java.io.ObjectInputStream.readObject()Ljava.lang.Object;(Unknown Source)
at java.util.HashMap.readObject(Ljava.io.ObjectInputStream V(Unknown Source)
at java.lang.LangAccessImpl.readObject(Ljava.lang.Class;Ljava.lang.Object;Ljava.io.ObjectInputStream V(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Ljava.lang.Object;Ljava.io.ObjectInputStream V(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Ljava.lang.Object;Ljava.io.ObjectStreamClass V(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Z)Ljava.lang.Object;(Unknown Source)
at java.io.ObjectInputStream.readObject0(Z)Ljava.lang.Object;(Unknown Source)
at java.io.ObjectInputStream.readObject()Ljava.lang.Object;(Unknown Source)

Thanks in Advance.
 
Thomas Thevis
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello an welcome to JavaRanch.

First of all, please make sure to read the Official policy on registered names. Secondly, please make sure to choose the right sub-forum for your question. Your chances to find someone to answer your questions will significantly increase
Back to your question:
It seems like the serialized Object defines another serial version id as the class definition accessible at de-serialization time.
Serializable classes may define a serializable version id which looks something like

This is done to ensure that at de-serialization time class definitions are compatible and the right fields are read in from the data streams.
Most probably, the class definition of your object to be de-serialized has changed over time and a new serial version id was generated. The new one is not compatible with the old one and thus a ClassCastException is thrown.

Hope that helps,
Thomas
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!