Java


JAVA.TYPE.MPSFA : Mutable Public Static Final Array (Java)

要旨

An array is declared as public final static, but its contents can be modified.

Use annotation @Immutable to identify classes that should be ignored by this check because they only undergo mutations that do not change observable behavior.

プロパティ

クラス名 Mutable Public Static Final Array (Java)
日本語クラス名 Mutable Public Static Final Array (Java)
クラス分類 信頼性 (reliability)
ニーモニック JAVA.TYPE.MPSFA
カテゴリー
CWE CWE:582 Array Declared Public, Final, and Static
  CWE:607 Public Static Final Field References Mutable Object
対応言語 Java で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Mutable Public Static Final Array (Java)"

// MyClass.java
public class MyClass {
    public final static int[] SMALL_PRIMES = new int[] { 2, 3, 5, 7, 11, 13, 17 };
    // 'Mutable Public Static Final Array (Java)' warning issued on previous line:
    // - array is final but its elements are not 
}

Resolution

Hide the field, for example by reducing its visibility to protected.

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

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