While attempting to deserialize (or unmarshal) a serialized object instance, you may generate an exception with a message similar to:
java.rmi.UnmarshalException: Error unmarshaling return; nested exception is: java.io.InvalidClassException: RMIParm; Local class not compatible: stream classdesc serialVersionUID=9468404698496832181 local class serialVersionUID=7528655624442771181at java.lang.Throwable.
(Compiled Code)at java.rmi.UnmarshalException. (Compiled Code)at RMIServer_Stub.getParm(RMIServer_Stub.java:40)at RMIClient.main(RMIClient.java:7)
This error occurs as a result of the class that was serialized and deserialized having been changed at some point. For example, it can occur when a server attempts to return an instance of an object to a client through Remote Method Invocation (RMI) while the client and server have different definitions of the class. This commonly occurs and can take place when the class is modified and recompiled on the client after being copied to the server. Another scenario might involve writing an object instance to disk, changing the source code for the class and recompiling it, then attempting to read the class instance stored in the disk file. In these cases, the reader’s version of the class definition is different from that of the writer, and the exception indicates that these are potentially incompatible versions of the same class.
However, it may be that the changes made to the class should not cause older versions to break, such as when new methods or variables are added. In this case, you can avoid problems unmarshalling old class instances by explicitly defining the Stream Unique Identifier (SUID). The SUID is nothing more than a value (usually the hash value for the class definition) that uniquely identifies a class definition. You can determine the SUID for a given serializable class by using the serialver utility included with the Java Development Kit (JDK):
This will produce output similar to:
myclass: static final long serialVersionUID = -3920827908241085518L;
Adding this statement to the class you wish to modify will allow you to successfully deserialize or unmarshal modified versions of the class. For more information, see the section on the versioning of serializable objects in the Object Serialization Specification document that is included with the JDK.