False positive for an if without else

Please provide

  • Operating system: Ubuntu
  • SonarLint plugin version: 7.3.0.59206
  • Programming language you’re coding in: Java
  • Is connected mode used: No

And a thorough description of the problem / question:

The following code produces a false positive:

    public static void main(String[] args) {
        if (args.length > 3) {
            foo(true);
        }
        foo(false);
    }

SonarLint reports issue java:S1126 “Replace this if-then-else statement by a single method invocation”.

This should not be issued because this is not an if-then-else statement and cannot be replaced by a single method invocation.

1 Like

Hi,

Welcome to the community!

Could you upgrade to the latest SonarLint version (7.4.0.60471) and see if this is still replicable, please?

 
Thx!
Ann

Hi Ann,

Yes, I’ve just upgraded to the latest version (7.4.0.60471) and the issue still exists.

Regards,
Klitos

Hi Klitos,

Thanks for testing. I’ll flag this for the developers.

 
Ann

Hello @klitos ,

There is indeed an issue. Thank you for reporting!
I have created a ticket about it.

Best,
Chrislain

1 Like