False positive infinite recursion from javabugs:S2190

SonarQube reports that the constructor is infinite recursion even though it is not

@Getter
@AllArgsConstructor
public class Key {

  private byte[] data;

  public Key(String asBase64) {
    this(Base64.getDecoder().decode(asBase64));
  }
}

SonarSource 8.1.0.65508
SonarQube 9.9.0.65466
Java 17.0.6
Lombok 1.18.26

Issue is not highlighted in the IDE, but is highlighted by SonarQube

I found another example in my code base which does not use lombok

public enum BankCountry {
  UNITED_STATES(BankCountrySettings.builder()
      .countryId(CountryId.US)
      .build()
  ),
  DEFAULT(CountryId.UNKNOWN),
  ;

  BankCountry(CountryId countryId) {
    this(BankCountrySettings.builder()
        .countryId(countryId)
        .build()
    );
  }

  BankCountry(BankCountrySettings settings) {
    ...
  }

Again, the recursion warning doesn’t show up in the IDE but does show up in SonarQube.

However, a potentially related false positive does show up in both IDE and SonarQube: BankCountry(BankCountrySettings settings) is flagged by java:S1144 as unused

Hello @lbenedetto ,

Thank you for your report. We fixed some problems with this rule in the presence of Lombok recently, the fix should be available in SQ 10.0 and is already deployed on SonarCloud.

Regarding your second example: could you share a self-contained reproducer and information about your build environment? We are looking into problems with this rule when there is some missing semantic information in the Java file (according to our Java parser), but did not manage to pinpoint an exact cause yet. Any additional information would be much appreciated.

Cheers,

Gyula

Sure. Looks like the issue is caused by accepting a class that is the result of a Lombok builder.

import lombok.Builder;

public enum EnumWithSupposedlyUnusedConstructor {
  A("a"),
  B(ClassWithLombokBuilder.builder()
      .a("b")
      .build()
  ),
  ;
  
  String a;

  EnumWithSupposedlyUnusedConstructor(String a) {
    this(ClassWithLombokBuilder.builder()
        .a(a)
        .build()
    );
  }

  // This constructor is marked as unused with java:S1144
  EnumWithSupposedlyUnusedConstructor(ClassWithLombokBuilder c) {
    a = c.a;
  }

  @Builder
  public static class ClassWithLombokBuilder {
    String a;
  }
}

Hello @lbenedetto ,

Thank you for reporting. There is indeed an issue regarding the unused constructor (rule S1144). I have created a ticket about it.

As for the other issues you illustrated with class Key and BankCountry, they no longer appear on SonarQube 10.0.

Best.

With SonarQube v10.8 (100206) I am still seeing the original false positive I reported in the Key class