Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A non-serializable class can be extended and its subclass can be made serializable, or it becomes serializable automatically if it derives from a serializable class. During deserialization of the subclass, the JVM calls the no-argument constructor of the most derived superclass that does not implement java.io.Serializable either directly or indirectly. When an object is deserialised the no-argument constructor of the most derived superclass that does not directly or indirectly implement java.io.Serializable is executed. In the code snippet that immediately follows, class A's no-argument constructor is called when C is deserialized because A does not implement Serializable. Subsequently, Object's constructor is invoked. This procedure cannot be carried out programmatically, consequently the JVM generates the equivalent bytecode at runtime. Typically, when the superclass's constructor is called by a subclass, the subclass remains on the stack. However, in deserialization this does not happen. Only the unvalidated bytecode is present. This allows any security checks within the superclass's constructor to be bypassed.

...