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

Read Time:32 Second

Description

The software 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.

Modes of Introduction:

– Implementation

 

 

Related Weaknesses

CWE-664
CWE-573

 

Consequences

Integrity, Other: Unexpected State, Quality Degradation

 

Potential Mitigations

Phase: Implementation

Description: 

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

Phase: Implementation

Description: 

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

CVE References