I think I have found a false positive while using the @Getter annotation from Project Lombok.
In the following example class I got the warning "Private fields only used as local variables in methods should become local variables" (squid:S1450).
public class Example {
@Getter
private String exampleField; // <-- squid:S1450
public Example(final String value) {
setExampleField(value);
}
private void setExampleField(final String exampleField) {
this.exampleField = exampleField;
}
}
Can someone confirm this? Is it a bug in the SonarQube rule or is there something wrong with my class or with my understanding of this rule or the @Getter annotation?
Just for the sake of completeness:
- Project lombok annotations or the generated methods are recognized correctly in other SonarQube rules. So I think my setup is fine.
- I have also tried to put the
@Getterannotation on class level and I got the same warning. - The warning is shown in SonarLint (in IntelliJ IDEA) and in the web interface of SonarQube. So I think it's not an error while executing the analyzer.
- I have bound the SonarLint pluign in IntelliJ IDEA to our SonarQube Server and this remote connection works.
I have tested with the following versions:
- SonarQube 6.0
- SonarQube Java Plugin 4.2
- SonarLint (for IntelliJ IDEA) 2.3.2
- IntelliJ IDEA 2016.2.5
- Java 8