[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)) {
if (Boolean.FALSE.equals(flag)) { // FP, since this evaluates to false in null- or non-Boolean-case
  • Operating system: Windows 10
  • SonarLint plugin version:
  • 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:

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 nor with the latest java analyzer
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).