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
Java


JAVA.STRUCT.UUFIELD : Unused Field (Java)

要旨

A field is never read and never written.

Fields constitute the state of an object, that is, they are meant to store information that survives across method calls. It is hence useless to store information in a field that is never read. Moreover, that behavior is actually harmful, since writing into a useless field hinders the garbage collector. It is also pointless to read data from a field that is never written, since the default value for the field will be found there. Note that there are situations when a field is written by reflection, which cannot be understood by analyzer, in general. This is often the case of fields auto-wired through dependency injection. The analyzer knows some specific patterns, typically marked through code annotations, but cannot foresee all possibilities.

プロパティ

クラス名 Unused Field (Java)
日本語クラス名 Unused Field (Java)
クラス分類 信頼性 (reliability)
ニーモニック JAVA.STRUCT.UUFIELD
カテゴリー
CWE CWE:1164 Irrelevant Code
対応言語 Available for Java and Kotlin.
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Unused Field (Java)"

public class Fields {
  private int f1;                         // Field Never Written (Java) warning issued here
  private final Object f2 = new Object(); // Field Never Read (Java) warning issued here
  private float f3;                       // Unused Field (Java) warning issued here

  public Fields() {
      System.out.println(f1);
  }

  public static void main(String args[]) {
      new Fields();
  }
}

In this example, all three fields are useless and could be removed, reducing the memory footprint of the instances of the class and helping the garbage collector.

解決法

Remove all fields that are never read or never written.

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

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

 

To report problems with this documentation, please visit https://support.codesecure.com/.