JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
A subclass of a non-cloneable class may be cloned.
The clone() method is used to generate a clone of an object, that is, a distinct instance with the same behavior as the original one. The default implementation in java.lang.Object checks that the object to clone either implements the java.lang.Cloneable interface or throws a java.lang.CloneNotSupportedException.
In order to clone an object it is generally sufficient to implement java.lang.Cloneable and use the default implementation of clone(). It is also possible to override that default implementation. Note that a class that inherits the default implementation allows its subclasses to implement java.lang.Cloneable and clone its instances.
| Class Name | clone Subclass of Non-clonable (Java) | ||||||
|---|---|---|---|---|---|---|---|
| Significance | reliability | ||||||
| Mnemonic | JAVA.CLASS.CLONE.SCNC | ||||||
| Categories |
|
||||||
| Availability | Available for Java and Kotlin. |
||||||
| Enabling | Checks for this warning class are disabled by default, and require strict Java analysis mode which is also disabled by default. To enable the checks, make the following changes to the project configuration file.
JAVA_ANALYSIS_STRICT_MODE = Yes WARNING_FILTER += allow class="clone Subclass of Non-clonable (Java)" |
// TestClone2.java public class TestClone2 { /* "clone Subclass of Non-clonable (Java)" warning issued here * - Subclasses of TestClone2 could exploit the default clone() method to get a * complete dump of the private data of the class instances. * - Resolve by defining the class as final. */ private int data; private String s; public TestClone2(int data, String s) { this.data = data; this.s = s; } }
Check that clone() is only redefined in classes that implement java.lang.Cloneable. Check that the default implementation of clone() is only used for classes that have explicitly declared to implement java.lang.Cloneable.
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.