Reputation: 93
I am getting an InvalidClassException when trying to open a serialized class. The class I am trying to open is quite complex and contains several other classes. Is there any way of telling which class is causing the exception?
I have set serialVersionUID on all classes and used transient variables where necessary. Presumably I have failed do to this for all classes, but I would like to find a way of locating the error without having to read through the code for every class.
Here is the stack trace I'm getting:
java.io.InvalidClassException: javax.swing.event.EventListenerList; local class incompatible: stream classdesc serialVersionUID = -5677132037850737084, local class serialVersionUID = -7977902244297240866
at java.base/java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:728)
at java.base/java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:2086)
at java.base/java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1933)
at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2259)
at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1768)
at java.base/java.io.ObjectInputStream$FieldValues.<init>(ObjectInputStream.java:2641)
at java.base/java.io.ObjectInputStream.readFields(ObjectInputStream.java:725)
at java.desktop/javax.swing.tree.DefaultTreeModel.readObject(DefaultTreeModel.java:704)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at java.base/java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1231)
at java.base/java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2458)
at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2292)
at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1768)
at java.base/java.io.ObjectInputStream$FieldValues.<init>(ObjectInputStream.java:2641)
at java.base/java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2492)
at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2292)
at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1768)
at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:543)
at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:501)
at combined.CombinedInterface.open(CombinedInterface.java:82)
at combined.CombinedInterface.main(CombinedInterface.java:18)
Also, this problem doesn't occur when I'm running the program in NetBeans, it only occurs when I'm running it from a jar file outside of Netbeans.
Upvotes: 0
Views: 224
Reputation: 718798
The class that is causing this is javax.swing.event.EventListenerList
.
Note that you should generally avoid serializing Swing classes. Many Swing classes state this in their javadocs:
"Serialized objects of this class will not be compatible with future Swing releases."
So if your use-case entails serializing with one version of Java and potentialiiy deserializing with another version, you are liable to run into this kind of problem.
Upvotes: 2