squid:S1258 FP in the Builder pattern

The rule incorrectly complains about a missing constructor (that initializes the class members) in the case of the Builder pattern.

Versions used:

  • SonarQube 6.7.6 LTS
  • SonarJava 5.11 (build 17289)
public class FooBuilder {

     private String someProperty;
     private String otherProperty;

     public Foo build() {
         if (someProperty == null || otherProperty == null) {
             throw new IllegalStateException("Builder is missing some data.");
         } else {
             return new Foo(someProperty, otherProperty);

     public FooBuilder withSomeProperty(String p) {
         this.someProperty = p;
         return this;
     public FooBuilder withOtherProperty(String p) {
         this.otherProperty = p;
         return this;


Hi, thanks for the feedback and thanks for the reproducer ! Indeed a FP ticket created to handle the issue https://jira.sonarsource.com/browse/SONARJAVA-3152

1 Like

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