Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable SQUID:UnusedProtectedMethod in Sonar for a class or method?

Tags:

java

sonarqube

I have a couple Hadoop map and reduce classes that override protected methods. Sonar flags these with:

Unused protected method
Plugin: squid    Key: UnusedProtectedMethod

I know there's a fix in Sonar that addresses this and that at some point my organization will use a version with that fix. In the meantime, I'd like to disable the warning. I've tried:

@SuppressWarnings("UnusedProtectedMethod")

and

@SuppressWarnings("SQUID.UnusedProtectedMethod")

to no avail.

@SuppressWarnings works for PMD issues, @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "blah") works for findbugs issues. Is there another variant for squid issues, or is it just not supported yet?

like image 257
Don Branson Avatar asked Mar 28 '12 17:03

Don Branson


2 Answers

Use

@SuppressWarnings("squid:UnusedProtectedMethod")

See also SonarQube Java Plugin FAQ - SuprressWarnings

This has been implemented in the SonarQube Java plugin version 2.8.

like image 90
Arend v. Reinersdorff Avatar answered Oct 06 '22 17:10

Arend v. Reinersdorff


I found that Squid supports only "all." From the squid plugin source, in SuppressWarningsAnnotationUtils.java:

private static final String VALUE = "\"all\"";
...


  public static boolean isSuppressAllWarnings(DetailAST ast) {
    DetailAST suppressWarningsAnnotation = getSuppressWarningsAnnotation(ast);
    if (suppressWarningsAnnotation != null) {
      DetailAST warningHolder = findWarningsHolder(suppressWarningsAnnotation);
      for (DetailAST warning = warningHolder.findFirstToken(TokenTypes.EXPR); warning != null; warning = warning.getNextSibling()) {
        if (warning.getType() == TokenTypes.EXPR) {
          DetailAST fChild = warning.getFirstChild();
          if (fChild.getType() == TokenTypes.STRING_LITERAL) {
            String text = warning.getFirstChild().getText();
            if (VALUE.equals(text)) {
              return true;
            }
          }
        }
      }
    }
    return false;
  }

There's discussion here: Support the annotation "@SuppressWarnings" at class and method level

like image 34
Don Branson Avatar answered Oct 06 '22 15:10

Don Branson