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?
Use
@SuppressWarnings("squid:UnusedProtectedMethod")
See also SonarQube Java Plugin FAQ - SuprressWarnings
This has been implemented in the SonarQube Java plugin version 2.8.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With