Versions Compared

Key

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

...

Returning references to internal object state (mutable or immutable) can render an application susceptible to information leaks and corruption of its objects' states, which consequently violates class invariants. Control flow can also be affected in some cases.

...

Related Vulnerabilities

Pugh [Pugh 2009] cites a vulnerability discovered by the Findbugs static analysis tool in the early betas of JDK 1.7 where the sun.security.x509.InvalidityDateExtension class returned a Date instance through a public accessor without creating defensive copies.

Related Guidelines

Bibliography

[API 2006]

Method clone()

[Bloch 2008]

Item 39. Make defensive copies when needed

[Goetz 2006]

3.2, Publication and Escape: Allowing Internal Mutable State to Escape

[Gong 2003]

9.4, Private Object State and Object Immutability

[Haggar 2000]

Practical Java Praxis 64. Use clone for immutable objects when passing or receiving object references to mutable objects

[Security 2006]

 

...

      Rule 05: Object Orientation (OBJ)Image Added