java - How to suppress multiple FindBugs warnings for the same line of code -
i discovered findbugs' @edu.umd.cs.findbugs.annotations.suppresswarnings annotation pretty cool , allows tell findbugs ignore warnings.
i've implemented own slf4j binding following recommendations take slf4j-simple , modify own logger , logger factory bindings, , i'm pleased works charm.
i ran find bugs on package contains slf4j binding , complaining line of code written original staticloggerbinder author (ceki gulku):
// avoid constant folding compiler, field must *not* final. publicstatic string requested_api_version = "1.6"; // !final findbugs complains field "isn't final should be". however, (very) smart people on @ slf4j thought of that, , placed surrounding comments provided above.
so, findbugs shut up, i've modified code per usual way of suppressing fb warnings:
@edu.umd.cs.findbugs.annotations.suppresswarnings("ms_should_be_final") public static string requested_api_version = "1.6"; when clean project , re-run findbugs, second warning on same line of code, time complaining:
this field never read. field public or protected, perhaps intended used classes not seen part of analysis. if not, consider removing class.
when add second warning suppression:
@edu.umd.cs.findbugs.annotations.suppresswarnings("ms_should_be_final") @edu.umd.cs.findbugs.annotations.suppresswarnings("urf_unread_public_or_protected_field") public static string requested_api_version = "1.6"; i compiler/syntax error eclipse:
duplicate annotation @suppresswarnings.
how can suppress multiple findbugs warnings on same line of code?
just list warning identifiers in array, within single annotation:
@edu.umd.cs.findbugs.annotations.suppresswarnings({ "ms_should_be_final", "urf_unread_public_or_protected_field"}) public static string requested_api_version = "1.6"; just standard java.lang.suppresswarnings, findbugs version has parameter of type string[]. single value, curly braces can omitted though make life easier.
Comments
Post a Comment