Calling overridable methods from the clone() method is dangerous for two reasons. First, a malicious subclass may override the method and affect the behavior of the clone() method. Second, a trusted subclass may observe the object in an uninitialized state because its construction may not have concluded.
Noncompliant Code Example
| Code Block | ||
|---|---|---|
| ||
Compliant Solution
| Code Block | ||
|---|---|---|
| ||