S2637 lombok.NonNull and lombok.Setter annotations false positive use case


A class field is reported to not be initialized while it is.


  • Eclipse IDE
    Version: 2020-12 (4.18.0)
    Build id: 20201210-1552
  • SonarLint
  • Lombok

Sample Code

import lombok.NonNull;
import lombok.Setter;

public class S2637FalsePositiveSampleCode {
    private String foo;

    public S2637FalsePositiveSampleCode(String foo) {

Lombok generates the method setFoo. Since the field foo is annotated with @NonNull, lombok adds a null check in the setFoo method.

However, an info is raised :

“foo” is marked “lombok.NonNull” but is not initialized in this constructor.

Hello @Stephan_Beuze, thanks for reporting this false positive.

I agree that there is a problem here. While investigating the code, I realized that even the vanilla Java code (similar to what Lombok will generate) is also subject to this false positive.

I therefore created a ticket to track this issue: SONARJAVA-3695.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.