[Java:S2589] Ignore for Boolean equals

This one is maybe related to SONARJAVA-3619 but not all the same

final Object flag = getFlag(); // can return null or non-Boolean
if (Boolean.TRUE.equals(flag)) {
  doSomething();
}
if (Boolean.FALSE.equals(flag)) { // FP, since this evaluates to false in null- or non-Boolean-case
  doSomethingElse();
}
doSomethingInNullCase();
  • Operating system: Windows 10
  • SonarLint plugin version: 7.0.0.52289
  • IntelliJ version: IntelliJ IDEA 2022.2.1 (Ultimate Edition) Build #IU-222.3739.54
  • Connected to SonarQube Developer Edition, Version 9.4 (build 54424)
  • Sonar Maven Plugin version: 3.9.1.2184

The FP is raised with SonarLint plugin as well as in SQ analysis with Maven.

Hey there.

Make sure to read this post before raising a thread here:

Specifically, we’re missing what product(s) you’re using, and what version (if applicable).

You’re right, I’ve added the information

Hi @fjakop,

I’m not able to reproduce a false-positive of rule S2589 with the java analyzer of SonarQube 9.4 (sonar-java-plugin 7.11.0.29148) nor with the latest java analyzer 7.13.0.29990.
If the getFlag() method is defined in the same java file that the snippet of code that you provide above, could you also share the content of the getFlag() method (or a simplified version that still produce the false-positive).