简体   繁体   中英

SonarQube false positive squid:S1450 for @Getter (lombok) annotated fields

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 @Getter annotation 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

You're right and I've created the following Jira ticket https://jira.sonarsource.com/browse/SONARJAVA-1924 . Thanks for your feedback !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM