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.0p0 Hot Tips | CONFIDENTIAL | CodeSecure Inc |
A method should be final, since it is not private, not static, and not overridden in any subclass.
| クラス名 | Method Should be final (Java) | |||
|---|---|---|---|---|
| 日本語クラス名 | Method Should be final (Java) | |||
| クラス分類 | 信頼性 (reliability) | |||
| ニーモニック | JAVA.CLASS.METH.NF | |||
| カテゴリー |
|
|||
| 対応言語 | Java で利用可能です。 |
|||
| 有効/無効設定 | このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル
(configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Method Should be final (Java)" |
// C.java public class C { private static int counter; private int id = getNextId(); @Override public String toString() { // ok: overridden in Sub return "#" + getId(); } protected int getId() { // "Method Should be final (Java)" warning issued here return id; } private int getNextId() { // ok: private return counter++; } public static int getNumberOfInstances() { // ok: static return counter; } }
// Sub.java public class Sub extends C { @Override public String toString() { // "Method Should be final (Java)" warning issued here return "sub" + super.toString(); } }
In this example, the programmer should make those two methods final, as follows.
// after modification
public class C {
private static int counter;
private int id = getNextId();
@Override
public String toString() {
return "#" + getId();
}
protected final int getId() {
return id;
}
private int getNextId() {
return counter++;
}
public static int getNumberOfInstances() {
return counter;
}
}
public class Sub extends C {
@Override
public final String toString() {
return "sub" + super.toString();
}
}
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。