开发者

Java: complete list of @SuppressWarnings(...) parameters (in Netbeans)?

Netbeans provides a lot of custom "hints", which are like warnings, only that most of them can't be suppressed (just disabled IDE-globally).

But now I looking at code which uses

@SuppressWarnings("element-type-mismatch")

to suppress a hint/warning which is called "suspicious method call" (such as remove(...) for a collection with a "wrong" type).

Well, I would never come to the ide开发者_StackOverflow中文版a to suppress a hint named "suspicious method call" with a SuppressWarnings-parameter called "element-type-mismatch", but apparently, it works.

So, is there a "magic list" of such parameters?

How, for instance, do I suppress the hint/warning "return of collection field"?

NOTE: for this similar question, "element-type-mismatch" is not listed.


After a brief look at the NB-sourcecode, I found these in some of the java.hint -classes:

@Hint(category="bitwise_operations", suppressWarnings="IncompatibleBitwiseMaskOperation")
@Hint(category="initialization", suppressWarnings="LeakingThisInConstructor")
@Hint(category="logging", suppressWarnings={"NonConstantLogger"}) //NOI18N
@Hint(category="logging", suppressWarnings={"ClassWithMultipleLoggers"}) //NOI18N
@Hint(category="logging", suppressWarnings={"ClassWithoutLogger"}, enabled=false) //NOI18N
@Hint(category="code_maturity", suppressWarnings="UseOfObsoleteCollectionType")
@Hint(category="initialization", suppressWarnings="OverridableMethodCallInConstructor")
@Hint(category="bitwise_operations", suppressWarnings="PointlessBitwiseExpression")
@Hint(category="code_maturity", suppressWarnings="CallToThreadDumpStack")
@Hint(category="bitwise_operations", suppressWarnings="ShiftOutOfRange")
@Hint(category="initialization", suppressWarnings="StaticNonFinalUsedInInitialization")
@Hint(category="code_maturity", enabled = false, suppressWarnings="UseOfSystemOutOrSystemErr")
@Hint(category="code_maturity", suppressWarnings="CallToPrintStackTrace")

Apparently, not all IDE-hints that are displayed as warnings are made suppressable... Don't know why though, 'cause the AbstractHint class wich many of them extends easily provides this ability... These are just the suppress-names though, so to find the mapping to the names of the warnings they represent, a deeper dig in the source is needed.


The documentation says:

Compiler vendors should document the warning names they support in conjunction with this annotation type. They are encouraged to cooperate to ensure that the same names work across multiple compilers.

Since NetBeans is using javac I think, here is a list.

See also this question.

If you are using another compiler, or some compiler plugin, search for its documentation.


Well the list is hard to find. Did find the sources of the hint classes of Netbeans.

So the 'list' is here. (also look at the sub packages; e.g. jdk and perf)

All classes can be supressed by using its camel cases name like:

// org.netbeans.modules.java.hints.jdk.UnnecessaryBoxing.java
@SuppressWarnings("UnnecessaryBoxing") 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜