Search code examples
sonarqubecheckstylesuppress-warnings

Honoring @SuppressWarnings with the sonar checkstyle plugin


Is there any possibility to configure SonarQube 5.1 with Checkstyle plugin to honor the @SuppressWarnings("deprecation") annotation. I do not want to turn off 'Avoid use of deprecated methods' rule, I just want to SonarQube honor the @SuppressWarnings annotation.

I have a Java code in which I need to use deprecated createValidator() method as following:

@SuppressWarnings("deprecation")
@Override
public javax.xml.bind.Validator createValidator() throws JAXBException {
    return contextDelegate.createValidator();
}

Java compiler does not warning when compiling code, but unfortunately SonarQube with CheckStyle plugin rise a issue:

squid:CallToDeprecatedMethod
Avoid use of deprecated methods

Solution

  • Squid is a different kind of beast. As suggested in the SonarQube docs, you'll have to use a slightly different syntax, e.g.:

    @SuppressWarnings("squid:CallToDeprecatedMethod")
    

    The string squid:CallToDeprecatedMethod is the SonarQube rule key.

    Unfortunately, this means adding two annotations to effectively suppress the deprecation warning. But afaik, it's the only way short of disabling the rule.