Question

After upgrading SonarQube from 4.0 to 4.2, I got a bunch of 'Unused private fields should be removed' errors from the classes with Lombok annotations.

I have

@SuppressWarnings("PMD.UnusedPrivateField")

declared at the beginning of all those classes. It worked fine when I was using SonarQube 3.7 and 4.0.

I use

mvn sonar:sonar

to generate the SonarQube report.

And this shows how my class look like:

@Data
@SuppressWarnings("PMD.UnusedPrivateField")
public class MyClass {
    private String field;
}

How can I get rid of those errors in version 4.2? Thanks.

Était-ce utile?

La solution

'Unused private fields should be removed' is the message generated by the internal SonarQube rule squid:S1068, whereas your @SuppressWarnings annotation disables the matching (and deprecated) PMD check.

You might want to check your quality profile, eventually disable this rule, or put some exclusions for the Lombok augmented classes.

Autres conseils

You can also individually exclude Sonar analysis on the fields using //NOSONAR as well which is nice cause you don't have to disable this rule globally if your @Data classes are scattered around your project, but this option also has the downside that it disables all Sonar analysis on this specific line.

@Data
public class MyClass {
    private String field; //NOSONAR
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top