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:S1258Non-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;
}