False positive on java:S2583 (Conditionally executed code should be reachable)

  • Windows 10 Pro
  • SonarLint plugin version: 10.0.1.77000
  • Programming language you’re coding in: Java
  • Is connected mode used: yes and no (the issue appears regardless)
    • Connected to SonarQube 10.2.1

I am getting a false positive on the rule java:S2583 for the following example code:

package test;

import lombok.extern.slf4j.Slf4j;
import java.time.LocalDateTime;

@Slf4j
public class TestRuleS2583 {

    // if used instead of @Slf4j then the issue does not appear
    // private static final Logger log = LoggerFactory.getLogger(TestRuleS2583.class);

    public String abc(boolean arg1) {
        // if the variable 'result' below is inlined then the issue does not appear
        boolean **result** = arg1 && method1(); // the issue appears here
        return result ? "a" : "b";
    }

    private boolean method1() {
        // if the logging below is commented out then the issue does not appear
        log.info("info");
        return LocalDateTime.now().getSecond() % 2 == 0;
    }
}

The issue gets reported by SonarLint only (not by SonarQube server - both 9.9 & 10.2).

Hi @zasmazka, Welcome to the community!

It is indeed an FP and thank you for reporting it. I have created a ticket and you can track its progress here.