False positive on missing constructor for classes with Lombok’s @Builder annotation

Sonar Lint Code smell S1258 says “Classes and enums with private members should have a constructor (java:S1258)”
But there are some exclusions to this rule . The first exclusion is "Class implementing a Builder Pattern (name ending with “Builder”). "

I am using Lombok’s @Builder annotation in my pojo . As the specification says , it generates an allArgsConstructor .

So my question here is is there any need to create a default constructor for my pojo class for this sonar rule to go away.?
I feel this sonar rule with lombok’s @Builder or @SuperBuilder annotations is a false positive.

Versions used:

  • MyEclipse Enterprise Version: 2021.5.24
  • SonarLint plugin for MyEclipse . Version - 7.1
  • JDK 11
  • lombok 1.18.22

Sample Code

@Builder //[S1258] SonarLint: Add a constructor to the class, or provide default values.
@JsonDeserialize(builder = Test.TestBuilder.class)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Test {
}

Hello @Nikhilrao and welcome to the community!

I agree that the issue should not be raised. My first observation is that we are not supporting @SuperBuilder, I created a ticket for that: SONARJAVA-4117.

But I’m still confused to see that @Builder is raising an issue, we should support it. Could you confirm that you are indeed using @Builder and that your project was correctly built and dependencies were correctly resolved?

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