...
When a hash table contains references to mutable data such as a series of Date
objects, each of those objects must also be copied by using a copy constructor or method. For further details, refer to rules "OBJ06-J. Defensively copy mutable inputs and mutable internal components" and "OBJ04-J. Provide mutable classes with copy functionality to safely allow passing instances to untrusted code safely."
Note that the keys of a hash table do not need to be deep copied; shallow copying of the references suffices because a hash table's contract dictates that its keys must produce consistent results to the equals()
and hashCode()
functions. Mutable objects whose equals()
or hashCode()
method results may be modified are not suitable keys.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="338146c1aa628c97-e251b0fe-433641b7-9a40a060-dc7271d759ee33652dcd6b5e"><ac:plain-text-body><![CDATA[ | [[API 2006 | AA. Bibliography#API 06]] | [method clone() | http://java.sun.com/javase/6/docs/api/java/lang/Object.html#clone()] | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="87379741964c5eb3-ba62ff2c-45a5451a-948e8054-963fa4ffdf9764d2f955dd0b"><ac:plain-text-body><![CDATA[ | [[Bloch 2008 | AA. Bibliography#Bloch 08]] | Item 39: Make defensive copies when needed | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="fdefff199cc6e1da-76ec16a9-499048af-ab6593c6-fcbb02434b4d9eebbca612b5"><ac:plain-text-body><![CDATA[ | [[Goetz 2006 | AA. Bibliography#Goetz 06]] | 3.2. Publication and Escape: Allowing Internal Mutable State to Escape | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d42bf15acae59ec9-b7b66e53-4aa84bf2-9d16b865-24cefd4c422ab096a80e45cf"><ac:plain-text-body><![CDATA[ | [[Gong 2003 | AA. Bibliography#Gong 03]] | 9.4 Private Object State and Object Immutability | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d2ee80f0da456f16-34607ff1-4d8c450f-8b4a862b-2c5f116fb47faf67d31a38bd"><ac:plain-text-body><![CDATA[ | [[Haggar 2000 | AA. Bibliography#Haggar 00]] | [Practical Java Praxis 64: Use clone for Immutable Objects When Passing or Receiving Object References to Mutable Objects | http://www.informit.com/articles/article.aspx?p=20530] | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="5ea02bf19e520ead-12150827-43ed413b-9148bd13-eb398ef0ee1c91f79237a726"><ac:plain-text-body><![CDATA[ | [[Security 2006 | AA. Bibliography#Security 06]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
...
OBJ04-J. Provide mutable classes with copy functionality to allow passing instances to untrusted code safely 04. Object Orientation (OBJ)