Java


JAVA.CLASS.CLONE.CCSM : Clone Call to Super is Missing (Java)

要旨

Method clone() does not call super.clone().

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.

プロパティ

クラス名 Clone Call to Super is Missing (Java)
日本語クラス名 Clone Call to Super is Missing (Java)
クラス分類 信頼性 (reliability)
ニーモニック JAVA.CLASS.CLONE.CCSM
カテゴリー
CWE CWE:580 clone() Method Without super.clone()
CERT-Java CERT-Java:MET53-J Ensure that the clone() method calls super.clone()
対応言語 Java で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Clone Call to Super is Missing (Java)"

// TestClone.java
public class CloneWithoutSuper implements Cloneable {
    @override
    public Object clone() throws CloneNotSupportedException { // Clone call to super is missing (Java) warning issued here
        Object returnMe = new CloneWithoutSuper();
        // ...
    }
}

public class MyClass extends CloneWithoutSuper{
    @override
    public Object clone() throws CloneNotSupportedException {
        Object returnMe = super.clone();
        // ...
    }
}

解決法

Check that clone() is implemented calling super.clone() instead of creating a new object of the class in which is declared.

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。