1

Is there a way to exclude sonar (version 4.0) rules with Java code?

Im using on my classes:

@SuppressWarnings("all")

But sonar don't remove all issues, we still have:

  • Correctness - Class defines field that masks a superclass field
  • Code duplication issues

I missing something?

EDIT: On sonar docs SuppressWarnings deactivates all rules, but don't work for me. This annotation only remove some rules.

Omar Hrynkiewicz
  • 502
  • 1
  • 8
  • 21
  • which version of sonar are you using? you might have to use the following plugin: [Switch off violation](http://docs.codehaus.org/display/SONAR/Switch+Off+Violations+Plugin) – Arnaud Potier Jan 29 '14 at 14:28

2 Answers2

0

You may want to refer to this FAQ to get some ideas. Also, as suggested in this question, you can use following code:

@edu.umd.cs.findbugs.annotations.SuppressWarnings(
    value = "NAME_OF_THE_FINDBUGS_RULE_TO_IGNORE",
    justification = "Why you choose to ignore it")
Community
  • 1
  • 1
Alex K.
  • 3,294
  • 4
  • 29
  • 41
0

Thanks to @ArnaudPotier and @AlexanderGavrilov

Answering my own post:

Is there a way to exclude sonar (version 4.0) rules with Java code?

Yes, but needs sonar configuration: http://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus#NarrowingtheFocus-IgnoreIssues

  • Regular expression on files added: javax\.annotation\.Generated
  • Annotation on class: @Generated(value = { "someValue" })

java.lang.@SuppressWarnings("all") doesn't work for all issues.

schnatterer
  • 7,525
  • 7
  • 61
  • 80
Omar Hrynkiewicz
  • 502
  • 1
  • 8
  • 21