False positive for javabugs:S2190 when referencing overloaded constructors

I have encountered a false positive on javabugs:S2190 on SonarQube version 9.9 (build 65466)

public class Foo {

    @NonNull
    private final UUID serviceUuid;

    public Foo(@NonNull BluetoothGattService service) {
        this(service.getUuid());
    }

    public Foo(@NonNull UUID serviceUuid) {
        this.serviceUuid = serviceUuid;
    }

}

The rule triggers a violation for the line containing:

this(service.getUuid());

Hello @Alix ,

I cannot reproduce the issue with the code example you provided. Could you please send a self-contained (meaning no 3rd party classes) reproducer?

Thank you,

Gyula

Hi, I can reproduce the issue with this snippet:

public class Foo {

    private final UUID uuid;

    public Foo(Bar bar) {
        this(bar.getUuid());
    }

    public Foo(UUID uuid) {
        this.uuid = uuid;
    }

    private static class Bar {

        UUID getUuid() {
            return UUID.randomUUID();
        }

    }

}

I’m unable to create a reproducible snippet (or upload exact code), but I get the same false positive for EProcessor(CustomObject init) constructor with code similar to this:

public abstract class CustomObject implements Serializable {
    int key;
    public CustomObject() {}
    public CustomObject(int key) {this.key = key;}
    public int getKey() {return key;}
}
public class CustomDocument extends CustomObject {
    public CustomDocument() { super(); }
    public CustomDocument(int key) {super(key);}
}
public abstract class AbstractProcessor {
    public AbstractProcessor(int key){}
}
public class EProcessor extends AbstractProcessor {
    public EProcessor(CustomObject init) {
        this((CustomDocument) init);
    }
    public EProcessor(CustomDocument init) {
        super(init.getKey());
    }
}

Hello @Alix ,

Unfortunately, I still cannot reproduce the issue on my side. I’ve prepared a small project from the example you provided and analyzed it on SonarCloud: https://sonarcloud.io/summary/overall?id=gyula-sallai-sonarsource_infinite-recursion-fp

I also tried to analyze the project on the SonarQube 9.9 LTS, and still could not reproduce the issue. Could you please share what build system you are using and how to modify the example project so that the FP appears?

Thank you,

Gyula

Hi Gyula,
I’ve made a copy of the project here:

The repositories will need re-configuration if you need to build the project, just replace https://artifacts.assaabloy.net/nexus/ with public URLs

Regards
Alix

Hello @Alix ,

I could also not reproduce the issue from the project you posted given its current state.
Do you think you could make it buildable by default?

Best.

Hi @chrislain ,
I’m not sure what you are asking for.

Maybe someone else can see this issue and can provide a better sample project?

Hi @Alix,

Sorry I was not clear. What I meant was that if you could configure the project correctly, e.g. make the gradle files point to public repositories, etc… it would be much easier for us to provide feedback.

Regards,
Chrislain