Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 idea 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.

like image 409
java.is.for.desktop Avatar asked Dec 11 '10 22:12

java.is.for.desktop


People also ask

What does @SuppressWarnings do in Java?

Use of @SuppressWarnings is to suppress or ignore warnings coming from the compiler, i.e., the compiler will ignore warnings if any for that piece of code. 1. @SuppressWarnings("unchecked") public class Calculator { } - Here, it will ignore all unchecked warnings coming from that class.

What does @SuppressWarnings mean?

@SuppressWarnings instruct the compiler to ignore or suppress, specified compiler warning in annotated element and all program elements inside that element. For example, if a class is annotated to suppress a particular warning, then a warning generated in a method inside that class will also be separated.

What is @SuppressWarnings unchecked Java?

@SuppressWarnings("unchecked") is used when Java generics just don't let you do what you want to, and thus, you need to explicitly specify to the compiler that whatever you are doing is legal and can be executed at the time of execution.

What is @SuppressWarnings unlikely ARG type?

This implies that the compiler may show "unwanted" warnings, or filter out invocations that are in fact bugs. For the former case, @SuppressWarnings("unlikely-arg-type") will document the exception both for the user and for the compiler.


1 Answers

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.

like image 60
Superole Avatar answered Oct 15 '22 10:10

Superole