[S1258] False positive on missing constructor for classes with Lombok's @Data annotation

Lombok’s @Data annotation creates a constructor:

@Data is a convenient shortcut annotation that bundles the features of @ToString , @EqualsAndHashCode , @Getter / @Setter and @RequiredArgsConstructor together

Unfortunately SonarLint rises a [S1258] false positive when this annotation is used on a class with no explicit constructor (or one of the Lombok’s annotations for creating a constructor):

Classes and enums with private members should have a constructor

Code smell

Major
java:S1258

Non-abstract classes and enums with non-static, private members should explicitly initialize those members, either in a constructor or with a default value.

Versions used:

  • InteliJ: IntelliJ IDEA 2021.1 (Ultimate Edition) Build #IU-211.6693.111
  • SonarLint plugin for InteliJ: 4.14.2.28348
  • JDK 16 (AdoptOpenJDK 16.0.0.j9)
  • lombok 1.18.20

Minimal code sample to reproduce:

@lombok.Data
public class Test { //[S1258] SonarLint: Add a constructor to the class, or provide default values.

    private String name;
}

Hello @MartinBG

Indeed, it seems that we are not correctly supporting this case.
Ticket created: SONARJAVA-3798.

Thanks for taking the time to repot this issue.

Best,
Quentin

1 Like

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