Why removing the variable from the object's class during deserialization doesn't throw an Exception? What does the "incompatible" changes mean in Serialization then? I have also changed the field of the class from non-static to static which according to Java Specifications
is incompatible.
Why removing the variable from the object's class during deserialization doesn't throw an Exception?
Because it isn't supposed to. See the Object Versioning Specification, #5.6.1 :
"Deleting fields - If a field is deleted in a class, the stream written will not contain its value. When the stream is read by an earlier class, the value of the field will be set to the default value because no value is available in the stream. However, this default value may adversely impair the ability of the earlier version to fulfill its contract."
and
"Changing a nonstatic field to static or a nontransient field to transient - When relying on default serialization, this change is equivalent to deleting a field from the class. This version of the class will not write that data to the stream, so it will not be available to be read by earlier versions of the class. As when deleting a field, the field of the earlier version will be initialized to the default value, which can cause the class to fail in unexpected ways."
Nothing there about throwing exceptions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.