Stream Unique Identifiers

Stream Unique Identifiers
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=7528655624442771181
at 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):

 
serialver myclass
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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值