结构: Simple
Abstraction: Variant
状态: Draft
被利用可能性: unkown
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.
cwe_Nature: ChildOf cwe_CWE_ID: 664 cwe_View_ID: 1000 cwe_Ordinal: Primary
cwe_Nature: ChildOf cwe_CWE_ID: 573 cwe_View_ID: 1000
cwe_Nature: ChildOf cwe_CWE_ID: 573 cwe_View_ID: 699
Language: {'cwe_Name': 'Java', 'cwe_Prevalence': 'Undetermined'}
范围 | 影响 | 注释 |
---|---|---|
['Integrity', 'Other'] | ['Unexpected State', 'Quality Degradation'] |
策略:
Call super.clone() within your clone() method, when obtaining a new object.
策略:
In some cases, you can eliminate the clone method altogether and use copy constructors.
The following two classes demonstrate a bug introduced by not calling super.clone(). Because of the way Kibitzer implements clone(), FancyKibitzer's clone method will return an object of type Kibitzer instead of FancyKibitzer.
bad Java
映射的分类名 | ImNode ID | Fit | Mapped Node Name |
---|---|---|---|
Software Fault Patterns | SFP28 | Unexpected access points |