# \[Java:S2589\] Ignore for Boolean equals

**URL:** <https://community.sonarsource.com/t/java-s2589-ignore-for-boolean-equals/71024>\
**Category:** Report False-positive / False-negative...\
**Tags:** java\
**Created:** [September 6, 2022, 8:23am UTC](https://community.sonarsource.com/t/java-s2589-ignore-for-boolean-equals/71024 "2022-09-06T08:23:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fjakop](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/fjakop/32/27085_2.png) [@fjakop](https://community.sonarsource.com/u/fjakop)\
**Post date:** [September 6, 2022, 8:23am UTC](https://community.sonarsource.com/t/java-s2589-ignore-for-boolean-equals/71024/1 "2022-09-06T08:23:26Z")

</div>

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

```java
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.

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [September 6, 2022, 10:32am UTC](https://community.sonarsource.com/t/java-s2589-ignore-for-boolean-equals/71024/2 "2022-09-06T10:32:41Z")

</div>

Hey there.

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

> [@How to Report a False-positive / False-negative](https://community.sonarsource.com/t/how-to-report-a-false-positive-false-negative/37022):
>
> Hey SonarSource Community! [False-positives happen](https://blog.sonarsource.com/false-positives-our-enemies-but-maybe-your-friends), as do false-negatives, and we’re eager to fix them. We are thrilled when our users report problems, so we can make our products better. What is a false-positive (FP)? A false-positive is when an issue is raised unexpectedly on code that should not trigger an issue, or where the suggested action doesn’t make any sense for the code. What is a false-negative (FN)? A false-negative is when an issue should be raised on a piece of code, but isn’t. …

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

---

<div class="post-metadata">

**Author:** ![fjakop](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/fjakop/32/27085_2.png) [@fjakop](https://community.sonarsource.com/u/fjakop)\
**Post date:** [September 7, 2022, 7:32am UTC](https://community.sonarsource.com/t/java-s2589-ignore-for-boolean-equals/71024/3 "2022-09-07T07:32:54Z")

</div>

You’re right, I’ve added the information

---

<div class="post-metadata">

**Author:** ![alban.auzeill](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alban.auzeill/32/36_2.png) [@alban.auzeill](https://community.sonarsource.com/u/alban.auzeill)\
**Post date:** [September 14, 2022, 9:16am UTC](https://community.sonarsource.com/t/java-s2589-ignore-for-boolean-equals/71024/6 "2022-09-14T09:16:22Z")

</div>

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).
