Versions Compared

Key

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

...

This example is also more amenable to efficient garbage collection, as described in rule "OBJ11-J. Write garbage-collection-friendly code."

Exceptions

Wiki Markup
*OBJ05-EX0:* According to Sun's Secure Coding Guidelines \[[SCG 2007|AA. Bibliography#SCG 07]\]:

If a class merely serves as a container for mutable inputs or outputs (the class does not directly operate on them), it may not be necessary to create defensive copies. For example, arrays and the standard collection classes do not create copies of caller-provided values. If a copy is desired so updates to a value do not affect the corresponding value in the collection, the caller must create the copy before inserting it into the collection, or after receiving it from the collection.

OBJ05-EX1: When callers expose only unmodifiable views of an object to a method, the method may freely use the unmodifiable view without defensive copying. This decision should be made early in the design of the API. Note that new callers of such methods must also expose only unmodifiable views. (See rule "SEC14-J. Provide sensitive mutable classes with unmodifiable wrappers.")

...

CERT C++ Secure Coding Standard

"OOP35-CPP. Do not return references to private data."

MITRE CWE

CWE ID 375, "Returning a Mutable Object to an Untrusted Caller" SCG 2007

Guideline 2-1 Create a copy of mutable inputs and outputs

Bibliography

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8bed76158a125e9a-071267df-483b4f5b-a591a67c-be27a68a6ae824dfe15fa846"><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="4fa5223d45657944-253248a7-46134baf-8b44831f-b17b9cef617ed1a83dd26630"><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="75270c9796374de6-cd1dce10-4a774f89-ac5bbd07-7c7ef5b089e25067a9d7f076"><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="638b3c11c69e3de1-3cb4e46f-4036477d-a06c985b-1a401e59f02bbb608a392a9d"><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="2e61f6f71a2ca4ec-6e78ba0b-45004bb4-b7fa880c-d05713507e0fa4851e1085f5"><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="3a425bcd64110839-2ed5f919-45c94150-9c9ba834-0758fb77fe0a869ef5b71bea"><ac:plain-text-body><![CDATA[

[[Security 2006

AA. Bibliography#Security 06]]

 

]]></ac:plain-text-body></ac:structured-macro>

...