0

0

@SuppressWarnings({ "unchecked", "

php中文网

php中文网

发布时间:2016-06-07 15:30:34

|

1102人浏览过

|

来源于php中文网

原创

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 this enum 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 type scope
    • 抑止:@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 variable
    • Include 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 this interface cannot be implemented
    • 抑止:なし
    • 代替手段:なし。実装しようとするとコンパイルエラーが出る。だったら警告じゃなくてエラーにしとけよ。

Deprecated and restricted API


  • Deprecated API
    • Signal use of deprecated API inside deprecated code
    • Signal 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 constructor SJIS() is not accessible due to restriction on required library C:\Program Files (x86)\Java\jre6\lib\charsets.jar
    • メッセージ:Access restriction: The type SJIS 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を展開すると

  1. Source attachment
  2. JavaDoc location
  3. Native library location
  4. Access rules

ってのが出てきます。そうです、ここです!

JREが提供するものは、だいたいjavaとかjavaxで始まる類のものは、

みんなアクセス可能であると書いています。

アクセス可能であるというinclude条件にマッチするもの以外をアクセス不許可にしています。

战刀API淘客自动采集系统
战刀API淘客自动采集系统

战刀API淘客自动采集系统是一个以php+MySQL进行开放的淘宝客网站程序。程序说明:1.老Y文章系统更改为php战刀API淘宝客系统。2.本程序就是基于"淘宝客基础API"开发出来的产品 。3.现在淘宝客API 重新开放申请 商品全自动更新。网站功能:1.现在淘宝客API 重新开放申请,本程序就是基于"淘宝客基础API"开发出来的产品,海量商品全自动更新

下载

どのJarにも現在は160のルールが設定されているはずです。

アクセスルールは3種類の分類があります。

  1. Forbidden
  2. Discouraged
  3. Accessible

JREとかのは、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 read
    • Ignore in overriding and implementing methods
    • Ignore 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 exception
    • Ignore in overriding and implementing method
    • Ignore exceptions documented with '@throws' or '@exception' tags
    • Ignore '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")

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
C++ 设计模式与软件架构
C++ 设计模式与软件架构

本专题深入讲解 C++ 中的常见设计模式与架构优化,包括单例模式、工厂模式、观察者模式、策略模式、命令模式等,结合实际案例展示如何在 C++ 项目中应用这些模式提升代码可维护性与扩展性。通过案例分析,帮助开发者掌握 如何运用设计模式构建高质量的软件架构,提升系统的灵活性与可扩展性。

4

2026.01.30

c++ 字符串格式化
c++ 字符串格式化

本专题整合了c++字符串格式化用法、输出技巧、实践等等内容,阅读专题下面的文章了解更多详细内容。

2

2026.01.30

java 字符串格式化
java 字符串格式化

本专题整合了java如何进行字符串格式化相关教程、使用解析、方法详解等等内容。阅读专题下面的文章了解更多详细教程。

1

2026.01.30

python 字符串格式化
python 字符串格式化

本专题整合了python字符串格式化教程、实践、方法、进阶等等相关内容,阅读专题下面的文章了解更多详细操作。

1

2026.01.30

java入门学习合集
java入门学习合集

本专题整合了java入门学习指南、初学者项目实战、入门到精通等等内容,阅读专题下面的文章了解更多详细学习方法。

20

2026.01.29

java配置环境变量教程合集
java配置环境变量教程合集

本专题整合了java配置环境变量设置、步骤、安装jdk、避免冲突等等相关内容,阅读专题下面的文章了解更多详细操作。

16

2026.01.29

java成品学习网站推荐大全
java成品学习网站推荐大全

本专题整合了java成品网站、在线成品网站源码、源码入口等等相关内容,阅读专题下面的文章了解更多详细推荐内容。

18

2026.01.29

Java字符串处理使用教程合集
Java字符串处理使用教程合集

本专题整合了Java字符串截取、处理、使用、实战等等教程内容,阅读专题下面的文章了解详细操作教程。

3

2026.01.29

Java空对象相关教程合集
Java空对象相关教程合集

本专题整合了Java空对象相关教程,阅读专题下面的文章了解更多详细内容。

6

2026.01.29

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号