False positive on java:S1165

Must-share information (formatted with Markdown):

  • which versions are you using:
    SonarQube Entreprise Edition v10.6 (92116)

Hello Sonar team,

Looks like we have a false positive with java:S1165 Make this “id” field final when using Lombok annotation.

Here is a reproducer

import lombok.EqualsAndHashCode;
import lombok.Value;
import lombok.experimental.NonFinal;

@Value
@EqualsAndHashCode(callSuper = true)
@NonFinal
public abstract class MyException extends Exception {
    private static final long serialVersionUID = 1L;
    long id;

    protected MyException(long id, String message) {
        super(message);
        this.id = id;
    }
}

On the line long id; Sonarqube (and SonarLint also) raise the issue Make this “id” field final
In this case the Lombok annotation @Value guarantees that the field id is final.

With :heart:
Xavier

Hello @Xav, thank you for reaching out and reporting this False Positive.

The usage of Lombok annotations is always a problem in static analysis since the Lombok-modified AST is not available during the analysis, for this reason we implement a filter to make exceptions.

In this specific case the logic defined in [SONARJAVA-3320] - Jira is indeed wrong. You can track the progress on the fix at [SONARJAVA-5132] - Jira.

Cheers,
Angelo

1 Like