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 |
Identify useless constructions of objects.
An object is created and not assigned, and its construction has no side-effects other than on the object itself.
Java allows a few expressions to be used as commands. Among them, object creation is allowed to be used as a command since it can in principle induce side-effects and hence have a computational sense. However, creation of objects that do not induce side-effects is useless and should be removed from the code; it might actually be the sign of a programming error.
| クラス名 | Unused Object (Java) | |||
|---|---|---|---|---|
| 日本語クラス名 | Unused Object (Java) | |||
| クラス分類 | 信頼性 (reliability) | |||
| ニーモニック | JAVA.STRUCT.UUOBJ | |||
| カテゴリー |
|
|||
| 対応言語 | Available for Java and Kotlin. |
|||
| 有効/無効設定 | このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル
(configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Unused Object (Java)" |
public class Creations {
public static boolean unnamed;
public static void main(String[] args) {
Test test = new Test(args.length > 0 ? args[0] : null); // ok: object assigned to a local variable
new Test("hello"); // "Unused Object (Java)" warning issued here
new Test(); // ok: constructor has side effect on field 'unnamed'
System.out.println(test);
}
private static class Test {
private final String name;
private Test(String name) {
this.name = name;
}
private Test() {
this.name = "no name";
unnamed = true;
}
@Override
public String toString() {
return name;
}
}
}
Check if the object creation was meant to have some side-effect and delete it.
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。
To report problems with this documentation, please visit https://support.codesecure.com/.