Umbra Wiki weakness weakness/CWE-580
Back to wiki

CWE-580 — clone() Method Without super.clone()

provenance: imported · CWE: CWE-580

CWE-580: clone() Method Without super.clone()

MITRE CWE weakness

Kind Weakness
Abstraction Variant
Status Draft
Likelihood of exploit

Description

The product contains a clone() method that does not call super.clone() to obtain the new object.

All implementations of clone() should obtain the new object by calling super.clone(). If a class does not follow this convention, a subclass's clone() method will return an object of the wrong type.

Common consequences

  • Integrity, Other: Unexpected State, Quality Degradation

Mitigations

Implementation — Call super.clone() within your clone() method, when obtaining a new object.

Implementation — In some cases, you can eliminate the clone method altogether and use copy constructors.

References

  • CWE page: https://cwe.mitre.org/data/definitions/580.html
  • CWE list: https://cwe.mitre.org/data/index.html