Non-static access code to static member. デフォルトレベル:Warning メッセージ: The static field ${クラス名}.${クラス変数名} should be accessed in a static way 抑止: @SuppressWarnings( static-access ) 代替手段:コードを直そう。 Indirect a
<link href=”/js/syntaxhighlighter/SyntaxHighlighter.css” rel=”stylesheet” type=”text/css” />
- Non-static access code to static member.
- デフォルトレベル:Warning
- メッセージ: The static field ${クラス名}.${クラス変数名} should be accessed in a static way
- 抑止:@SuppressWarnings(“static-access”)
- 代替手段:コードを直そう。
- Indirect access to static member.
- デフォルトレベル:Ignore
- メッセージ: The static field ${クラス名}.${変数名} should be accessed directly
- 抑止:@SuppressWarnings(“static-access”)
- 代替手段:コードを直そう。
- Unqualified access to instance field
- デフォルトレベル:Ignore
- メッセージ: Unqualified access to the field ${クラス名}.{インスタンス変数名}
- 抑止:@SuppressWarnings(“unqualified-field-access”)
- 代替手段:thisを付ければ普通に消える。
- Undocumented empty block
- デフォルトレベル:Ignore
- メッセージ: Empty block should be documented
- 抑止:なし
- 代替手段:コメントを入れてください。
- Access to a non-accessible member of an enclosing type
- デフォルトレベル:Ignore
- メッセージ: Read access to enclosing field ${クラス名}.${変数名} is emulated by a synthetic accessor method
- 抑止:@SuppressWarnings(“synthetic-access”)
- 代替手段:可能であれば、変数にfinal修飾子を付けるだとかアクセス修飾子を考える。
- Method with a constructor name
- デフォルトレベル:Warning
- メッセージ:this method has a constructor name
- 抑止:なし。
- 代替手段:素直にメソッド名を変えます。
- Parameter assignment
- デフォルトレベル:Ignore
- メッセージ:The parameter ${パラメータ変数名} should be assigned
- 抑止:なし
- 代替手段:パラメータ変数にfinal付ける習慣を持つと、コンパイルエラーにしてくれるよ。
- Non-externalized strings (missing/unused $NON-NLS$ tag)
- デフォルトレベル:Ignore
- メッセージ(missing):Non-externalized string literal; it should be followed by //$NON-NLS-$
- メッセージ(unused):Unnecessary $NON-NLS$ tag
- 抑止:@SuppressWarnings(“nls”)
- 代替手段(unused):消すよ普通。
- 代替手段(missing):外部化ウィザードでやる。
- $NON-NLS$の数字の秘密はこういうことだよ。String[] a = {“”,””}; //$NON-NLS-1$ //$NON-NLS-2$
Potential programming problems
- Serializable class without serialVersionUID
- デフォルトレベル:Warning
- メッセージ:The serializable class ${クラス名} does not declare a static final serialVersionUID field of type long
- 抑止:@SuppressWarnings(“serial”)
- 代替手段:生成シリアルバージョンを入れる。
- Assignment has no effect (e.g. ‘x = x’)
- デフォルトレベル:Warning
- メッセージ:The assignment to variable object has no effect
- 抑止:なし。
- 代替手段:コードを直そう。きっとそのコードは不要だ。
- Possible accidental boolean assignment (e.g. ‘if(a = b)‘)
- デフォルトレベル:Ignore
- メッセージ:Possible accidental assignment in place of a comparison. A condition expression should not be reduced to an assignment
- 抑止:なし
- 代替手段:コードが合ってれば直す必要はないが、ずっと警告出てしまうから、出ない書き方すれば?
- ‘finally’ does not complete normally
- デフォルトレベル:Warning
- メッセージ:finally block does not complete normally
- 抑止:@SuppressWarnings(“finally”)
- 代替手段:特になし。致命的なバグの可能性もあるので見逃して良い警告じゃない。
- Empty statement
- デフォルトレベル:Ignore
- メッセージ:Unnecessary semicolon
- 抑止:なし
- 代替手段:セミコロンを消す。
- Using a char array in string concatenation
- デフォルトレベル:Warning
- メッセージ:Must explicitly convert the char[] to a String
- 抑止:なし
- 代替手段:まあ、StringBuilderとかで連結しましょう。
- Hidden catch block
- デフォルトレベル:Warning
- メッセージ:Unreachable catch block for ${例外クラス名}. Only more specific exceptions are thrown and handled by previous catch block(s).
- 抑止:@SuppressWarnings(“hiding”)
- 代替手段:特に思いつかない。
- Inexpect type match for vararg arguments
- デフォルトレベル:Warning
- メッセージ:The argument of type null should explicitly be cast to ${可変長クラス名}[] for the invocation of the varargs method foo(${可変長クラス名}…) from type ${クラス名}. It could alternatively be cast to ${可変長クラス名} for a varargs invocation
- 抑止:なし
- 代替手段:メッセージに書いてる通りキャストする。
- Boxing and unboxing conversions
- デフォルトレベル:Ignore
- メッセージ(boxing):The expression of type ${プリミティブ型} is boxed into ${ラッパー型}
- メッセージ(unboxing):The expression of type ${ラッパー型} is unboxed into ${プリミティブ型}
- 抑止:@SuppressWarnings(“boxing”)
- 代替手段:明示的に書くこと。
- Enum type constant not covered on ‘switch’
- デフォルトレベル:Ignore
- メッセージ:The enum constant ${他の定数名} needs a corresponding case label in thisenum switch on ${Enumクラス名}
- 抑止:@SuppressWarnings(“incomplete-switch”)
- 代替手段:なし。必要ないのを全部書くのは馬鹿らしいよね。
- ‘switch’ case fall-through
- デフォルトレベル:Ignore
- メッセージ:Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above
- 抑止:@SuppressWarnings(“fallthrough”)
- 代替手段:メッセージにある通りか、またはバグならbreakを書くとか。
本文来源gaodai.ma#com搞##代!^码7网
- Null pointer access
- デフォルトレベル:Warning
- メッセージ:Null pointer access: The variable i can only be null at this location
- 抑止:@SuppressWarnings(“null”)
- 代替手段:たぶんバグ、きっとバグ、だから直そう。
- Potential null pointer access
- デフォルトレベル:Warning
- メッセージ:Potential null pointer access: The variable i may be null at this location
- 抑止:@SuppressWarnings(“null”)
- 代替手段:その地点までにnullである場合は例外にしちゃうかもね。
- Comparing identical values (‘x == x’)
- デフォルトレベル:Warning
- メッセージ:Comparing identical expressions
- 抑止:なし
- 代替手段:同じ物を比較してんじゃないよ!ってことだよ。
- Missing synchronized modifier on inherited method
- デフォルトレベル:Ignore
- メッセージ:The method ${クラス名}.{メソッドシグニチャ} is overriding a synchronized method without being synchronized
- 抑止:なし
- 代替手段:synchronizedを付ける。
- Class overrides ‘equals()‘ but not ‘hashCode()‘
- デフォルトレベル:Ignore
- メッセージ:The type ${クラス名} should also implement hashCode() since it overrides Object.equals()
- 抑止:なし
- 代替手段:hashCodeをオーバーライドする。とりあえずフィールドから自動作成するクセを付けよう。
- Dead Code (e.g. ‘if(false)‘)
- デフォルトレベル:Warning
- メッセージ:Dead code
- 抑止:なし
- 代替手段:普通に消す。