non-static access code to static member. デフォルトレベル:warning メッセージ: the static field ${クラス名}.${クラス変数名} should be accessed in a static way 抑止: @suppresswarnings( static-access ) 代替手段:コードを直そう。 indirect a
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を書くとか。
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抑止:なし代替手段:普通に消す。
name shadowing and conflicts
field declaration hides another field or variableデフォルトレベル:ignoreメッセージ:the field ${クラス名}.${フィールド名} is hiding a field from type ${クラス名}メッセージ:the field ${クラス名}.${フィールド名} is hiding another local variable defined in an enclosing typescope抑止:@suppresswarnings(hiding)代替手段:スーパークラスおよびサブクラスのフィールドのアクセス修飾子が妥当か考えてみる。
local variable declaration hides another field or variableデフォルトレベル:ignoreメッセージ:the local variable name is hiding a field from type ${クラス名}抑止:@suppresswarnings(hiding)代替手段:どちらかの名前を変える。
local variable declaration hides another field or variableinclude constructor or setter method parametersデフォルトレベル:ignoreメッセージ:the parameter name is hiding a field from type ${クラス名}抑止:@suppresswarnings(hiding)代替手段:どちらかの名前を変える。パラメーターに@suppresswarningsを付けることはお勧めしません。ひどく読みにくくなります。
type parameter hides another typeデフォルトレベル:warningメッセージ:the type parameter ${型パラメータ名} is hiding the type ${クラス名}抑止:@suppresswarnings(hiding)代替手段:クラス名の変更よりは、型パラメータの名前を変更した方がいい。おかしなことに、総称型クラスとそのインナークラス(e)で試したら、この警告は出なかった。変だ。バグ?
method does not override package visible methodデフォルトレベル:warningメッセージ:the method ${クラス名}.${メソッド名}() does not override the inherited method from ${クラス名} since it is private to a different package抑止:なし代替手段:なんだかパッケージプライベートにするように促されるんだけど意味ないよ。
interface method conflicts with protected 'object' methodデフォルトレベル:warningメッセージ:the return type is incompatible with object.clone(), thus thisinterface cannot be implemented抑止:なし代替手段:なし。実装しようとするとコンパイルエラーが出る。だったら警告じゃなくてエラーにしとけよ。
deprecated and restricted api
deprecated apisignal use of deprecated api inside deprecated codesignal overriding or implementing deprecated methodデフォルトレベル:warningメッセージ:the method ${メソッド名} from the type ${クラス名} is deprecated抑止:@suppresswarnings(deprecation)代替手段:なし。
forbidden reference (access rule)デフォルトレベル:error以下はメッセージ例、汎化して書くのが大変だったのでそのまま書きます。これはsun.nio.cs.ext.sjisをデフォルトコンストラタを使ってnewしています。メッセージ:access restriction: the constructorsjis() is not accessible due to restriction on required library c:\program files (x86)\java\jre6\lib\charsets.jarメッセージ:access restriction: the typesjis is not accessible due to restriction on required library c:\program files (x86)\java\jre6\lib\charsets.jar抑止:@suppresswarnings(restriction)代替手段:そもそもがエラーですから、jdkを実装をしてる人くらいしか使わないはずです。
アクセスルールとは何か!?
eclipsewikiでは?で飛ばしていたのでちょっと僕の実験結果を書いておくよ。
ビルドパスの構成で、jreシステムライブラリーは必ず入れてると思います。
では、そのライブラリを展開すると、いくつかのjarが表示されるでしょう。
そのjarを展開すると
source attachment javadoc locationnative library locationaccess rulesってのが出てきます。そうです、ここです!
jreが提供するものは、だいたいjavaとかjavaxで始まる類のものは、
みんなアクセス可能であると書いています。
アクセス可能であるというinclude条件にマッチするもの以外をアクセス不許可にしています。
どのjarにも現在は160のルールが設定されているはずです。
アクセスルールは3種類の分類があります。
forbiddendiscouragedaccessiblejreとかのは、accessibleとforbiddenしか使ってないはずです。
クラスのアクセス修飾子とは関係がないっす。
discouraged reference (access rules)デフォルトレベル:warning以下の例は、私の別のjavaプロジェクトをビルドパスに含め、そのプロジェクトにdiscouragedなアクセスルールを設定して行った場合の例を元にしています。他に、importや変数の型にも反応します。メッセージ:discouraged access: the type ${クラス名} is not accessible due to restriction on required project ${プロジェクト名}抑止:@suppresswarnings(restriction)代替手段:なし。メソッドにsuppresswarnignsを付けても、たいていの場合はimport分にも付けるためクラスにsuppresswarningsを付けることになり、メソッドに付けた方は不要なアノテーションとみなされるでしょう。
unnecessary code
local variable is never readデフォルトレベル:warningメッセージ:the local variable ${ローカル変数名} is never read抑止:@suppresswarnings(unused)代替手段:要らないなら消しておこう。
parameter is never readignore in overriding and implementing methodsignore parameters documented with '@param' tagデフォルトレベル:ignoreメッセージ:the parameter a is never read抑止:@suppresswarnings(unused)代替手段:なし。消すとシグニチャーが変わるので影響がデカイ。
unused importデフォルトレベル:warningメッセージ:the import ${クラス名} is never used抑止:@suppresswarnings(unused)代替手段:クラスにunusedが付くよりは、import編成した方が良い。
unused local or private memberデフォルトレベル:warningメッセージ:the type ${ローカルクラス名} is never used locallyメッセージ:the type ${privateなインナークラス名} is never used locallyメッセージ:the field ${クラス名}.${private変数名} is never read locally抑止:@suppresswarnings(unused)代替手段:使わないなら消そう。
redundant null checkデフォルトレベル:ignoreメッセージ:null comparison always yields false: the variable a cannot be null at this location抑止:@suppresswarnings(null)代替手段:絶対にnullにならないので判定を消した方が良い。
unnecessary 'else' statementデフォルトレベル:ignoreメッセージ:statement unnecessarily nested within else clause. the corresponding then clause does not complete normally抑止:なし代替手段:elseではなくす。けっこう人によって好みが現れるかもしれない。
unnecessary cast or 'instanceof' operationデフォルトレベル:ignoreメッセージ:unnecessary cast from ${クラス名} to ${クラス名}メッセージ:the expression of type ${クラス名} is already an instance of type ${クラス名}抑止:@suppresswarnings(cast)代替手段:大きな害はないけれど、不要なものは消した方が良い。
unnecessary declaration of thrown exceptionignore in overriding and implementing methodignore exceptions documented with '@throws' or '@exception' tagsignore 'exception' and 'throwable'デフォルトレベル:ignoreメッセージ:the declared exception ${例外クラス名} is not actually thrown by the method ${メソッド名} from type ${クラス名}抑止:@suppresswarnings(unused)代替手段:使ってないなら消す。インターフェースからの物でも、範囲を狭めるなら許される。
unused 'break' or 'continue' labelデフォルトレベル:warningメッセージ:the label ${ラベル名} is never explicitly referenced抑止:@suppresswarnings(unused)代替手段:使ってないなら消す。そもそもラベル使うほどの特殊なコードを書く人は少ないだろうが…。使ったこと無い人が多いから付け加えておく。break ラベル名;やcontinue ラベル名;って使うんだよ。2つ以上ネストしたループで使うことになるだろう。少なくても日本人がこんなコードは書いてるところを見たことがない。そうだな、sql文のパーサー、csvの解析をする時にこのコーディングを使うとより高速になるだろう。
redundant super interfaceデフォルトレベル:ignoreメッセージ:redundant superinterface ${インターフェース名} for the type ${サブクラス名}, already defined by ${スーパークラス名}抑止:@suppresswarnings(unused)代替手段:普通はサブクラスにあるのを消す。まあ、意図するところがあるならば、スーパークラスでimplementsしない。
generic types
unchecked generic type operationデフォルトレベル:warningメッセージ:type safety: the method ${メソッド名} belongs to the raw type ${クラス名}. references to generic type ${総称型クラス名} should be parameterized抑止:@suppresswarnings(unchecked)代替手段:型パラメータが分かる場合はそれを使用する。
usage of a raw typeデフォルトレベル:warningメッセージ:${クラス名} is a raw type. references to generic type ${総称型クラス名} should be parameterized抑止:@suppresswarnings(unchecked)代替手段:出来るだけraw型を使わないようにする。ただし設計時にかなり考慮しないと完璧に回避することは困難。
generic type parameter declared with final type boundデフォルトレベル:warningメッセージ:the type parameter ${型パラメータ名} should not be bounded by the final type ${クラス名}. final types cannot be further extended抑止:なし代替手段:extendedな書き方をしない。継承出来ないものを上限におくのだから、そのクラスしか許さないと言っているだけです。
annotations
missing '@override' annotationデフォルトレベル:ignoreメッセージ:the method ${メソッド名} of type ${サブクラス名} should be tagged with @override since it actually overrides a superclass method抑止:なし代替手段:足らない@overrideを足す。
missing '@deprecated' annotationデフォルトレベル:ignoreメッセージ:the deprecated method ${メソッド名} of type ${クラス名} should be annotated with @deprecated抑止:@suppresswarnings(dep-ann)代替手段:@deprecatedを付けた方が良いと思う。
annotation is used as super interfaceデフォルトレベル:warningメッセージ:the annotation type ${アノテーション名} should not be used as a superinterface for ${インターフェース名}抑止:なし代替手段:間違った使い方だろうから直した方がいいね。
unhandled token in '@suppresswarnings'デフォルレベル:warningメッセージ:unsupported @suppresswarnings(${ハンドル出来ない文字列})抑止:なし代替手段:クイックフィックスで出てくるのはミススペル程度のものです。
unused '@suppresswarnings' annotationsデフォルトレベル:warningメッセージ:unnecessary @suppresswarnings(${ハンドル出来る文字})抑止:なし代替手段:要らないから消す。
コンパイラのerror/warningから紐解けた@suppresswarningsの一覧
@suppresswarnings(boxing)@suppresswarnings(cast)@suppresswarnings(dep-ann)@suppresswarnings(deprecation)@suppresswarnings(fallthrough)@suppresswarnings(finally)@suppresswarnings(hiding)@suppresswarnings(incomplete-switch)@suppresswarnings(nls)@suppresswarnings(null)@suppresswarnings(restriction)@suppresswarnings(serial)@suppresswarnings(static-access)@suppresswarnings(synthetic-access)@suppresswarnings(unchecked)@suppresswarnings(unqualified-field-access)@suppresswarnings(unused)