# False positive: Java: NullPointerException could be thrown

**URL:** <https://community.sonarsource.com/t/false-positive-java-nullpointerexception-could-be-thrown/36619>\
**Category:** Report False-positive / False-negative...\
**Tags:** java\
**Created:** [January 6, 2021, 3:06pm UTC](https://community.sonarsource.com/t/false-positive-java-nullpointerexception-could-be-thrown/36619 "2021-01-06T15:06:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rodrigolopes](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/rodrigolopes/32/18163_2.png) [@rodrigolopes](https://community.sonarsource.com/u/rodrigolopes)\
**Post date:** [January 6, 2021, 3:06pm UTC](https://community.sonarsource.com/t/false-positive-java-nullpointerexception-could-be-thrown/36619/1 "2021-01-06T15:06:54Z")

</div>

SonarQube Version 8.5.1 (build 38104)

Null condition is checked in a ternary (elvis) operator.

 ![Capture](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/6/b/6bc87ee940765a9d869dbcbd923472eb3d930e7d.jpeg)

```auto
 public void consumerError(ErrorMessage errorMessage) {
        String payload = (errorMessage.getOriginalMessage() != null && errorMessage.getOriginalMessage().getPayload() != null)
                ? errorMessage.getOriginalMessage().getPayload().toString()
                : errorMessage.getPayload().getMessage();
        LOGGER.error("Error receiving event with message: {}", payload, errorMessage.getPayload());
    }

```

---

<div class="post-metadata">

**Author:** ![Quentin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/quentin/32/74716_2.png) [@Quentin](https://community.sonarsource.com/u/Quentin)\
**Post date:** [January 7, 2021, 3:56pm UTC](https://community.sonarsource.com/t/false-positive-java-nullpointerexception-could-be-thrown/36619/2 "2021-01-07T15:56:06Z")

</div>

Hello @rodrigolopes and welcome to the SonarSource community!

You can have a look at this thread for a similar problem:

> [@Multiple false positives after upgrade to SonarQube 8.5.1](https://community.sonarsource.com/t/multiple-false-positives-after-upgrade-to-sonarqube-8-5-1/34271):
>
> We recently upgraded from 8.4.1 to 8.5.1. After this upgrade we have been hit with dozens of false positives surrounding null checks, such as the one seen in this screenshot: The line immediately before the issue shows a null check for agenda.getBody(), so it cannot be null at the time getJobs() is called. I am aware that some are caused by SonarQube not being able to see null checks that happen in called methods, but this clearly has the null check in the same expression. Has anyo…

Hope this clarifies the situation.

Best,  
Quentin

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [January 14, 2021, 3:56pm UTC](https://community.sonarsource.com/t/false-positive-java-nullpointerexception-could-be-thrown/36619/3 "2021-01-14T15:56:23Z")

</div>

Closed on January 14, 2021, 3:56pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
