Honoring @SuppressWarnings with the sonar checkstyle plugin

14,316

Solution 1

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.

Solution 2

Squid is a name or number of Sonar Rule, no relationship to checkstyle, all checkstyle rules are described at http://checkstyle.sourceforge.net/checks.html

Share:
14,316

Related videos on Youtube

Marcin
Author by

Marcin

Updated on June 04, 2022

Comments

  • Marcin
    Marcin almost 2 years

    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
    
  • KumarAnkit
    KumarAnkit over 5 years
    why two, we can use both the annotations in the single annotation use?
  • barfuin
    barfuin over 5 years
    Sure, you can @SuppressWarnings({"deprecation", "squid:CallToDeprecatedMethod"}), but that's syntactic sugar ;-) @KumarAnkit