Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by NavBot (vkp) v1.0

...

Wiki Markup
There is no need to copy immutable sub-objects. Also, avoid using the sub-object's {{clone()}} method because it can be overridden when the sub-object's class is non-final. Moreover, it produces only a shallow copy. The sub-objects ({{date}}) themselves must be non-final so that defensive copying can occur. It is also inadvisable to use the {{writeUnshared()}} and {{readUnshared()}} methods as an alternative \[[Bloch 2008|AA. Java References#BlochBibliography#Bloch 08]\].

Risk Assessment

Failure to defensively copy mutable components during deserialization can violate the immutability contract of an object.

...

Wiki Markup
\[[API 2006|AA. Java References#APIBibliography#API 06]\]
\[[Sun 2006|AA. Java References#SunBibliography#Sun 06]\] "Serialization specification: A.6  Guarding Unshared Deserialized Objects"
\[[Bloch 2008|AA. Java References#BlochBibliography#Bloch 08]\] Item 76: "Write readObject methods defensively"

...