score:34

Accepted answer

instead of using filters, you can also use the suppresswarnings annotation. you must use the annotation out of the findbugs package, meaning you either need an import or use the fully qualified name of it. this is because other than the suppresswarnings from the jdk it has retention "class", which is needed because findbugs operates on the compiled bytecode instead of source code.

example:

@edu.umd.cs.findbugs.annotations.suppresswarnings(
    value="eq_compareto_use_object_equals", 
    justification="because i know better")

there's one corner case where you probably should not be using the annotation: if your code is library code that ends up in a jar, that could be used by other projects and you're still on java5. the reason for this is a bug in the jdk which crashes javac if the annotation is not in the classpath.

score:0

on another hand - if you are using such automated code review tool that highlights potential problems according to widely known recommendations, maybe you should adhere to it's recommendations? think of people who will be maintaining code after you.

what if the code changes after time?

score:6

probably by adding a filter as parameter of findbugs

match clauses can only match information that is actually contained in the bug instances

<match>
   <class name="com.foobar.myclass" />
   <method name="mymethod" />
   <bug pattern="eq_compareto_use_object_equals" />
</match>

Related Query

More Query from same tag