# C#: False positive '@object' is null on at least one execution path

**URL:** <https://community.sonarsource.com/t/c-false-positive-object-is-null-on-at-least-one-execution-path/95984>\
**Category:** Report False-positive / False-negative...\
**Tags:** csharp, sonarqube-cloud\
**Created:** [July 19, 2023, 12:50pm UTC](https://community.sonarsource.com/t/c-false-positive-object-is-null-on-at-least-one-execution-path/95984 "2023-07-19T12:50:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_Wtyhk](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/m_wtyhk/32/46095_2.png) [@M\_Wtyhk](https://community.sonarsource.com/u/M_Wtyhk)\
**Post date:** [July 19, 2023, 12:50pm UTC](https://community.sonarsource.com/t/c-false-positive-object-is-null-on-at-least-one-execution-path/95984/1 "2023-07-19T12:50:34Z")

</div>

Hi,

could you please take a look at this code:

```auto
ObjectInstance object = null;
        if (object?.Value is not Table || (object.Value is Table t && t.isModified()))
        {
            string falsePositive = "I'll never check second object.Value";
        }

```

In SonarCloud I get this error:  
 ![obraz](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/e/8/e8ef9085ae9120b1e4e055cdd6e2dcf7c76a1e69.png)

According to my knowledge and VisualStudio it’s a false positive. If object is null in the first condition, then it will never check the second one, because it is already checked here **object?.Value is not Table**.

![obraz](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/d/c/dc9838b7ea26fe767d803560896af0cc787911fd.png)

Could you please help me find a solution to that issue?

---

<div class="post-metadata">

**Author:** ![antonio.aversa](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/antonio.aversa/32/40757_2.png) [@antonio.aversa](https://community.sonarsource.com/u/antonio.aversa)\
**Post date:** [July 25, 2023, 7:28am UTC](https://community.sonarsource.com/t/c-false-positive-object-is-null-on-at-least-one-execution-path/95984/4 "2023-07-25T07:28:13Z")

</div>

Hi @M_Wtyhk , thanks for reporting this issue.

I confirm I can reproduce the issue, which is indeed a False Positive case for rule [S2259](https://sonarsource.github.io/rspec/#/rspec/S2259/csharp).

A [GitHub issue](https://github.com/SonarSource/sonar-dotnet/issues/7665) has been created in the GitHub repo of the .NET Analyzers, to fix the False Positive case.

Waiting for the issue to be fixed, you can mark the issue in SonarCloud as a False Positive through the issues interface.

Best regards,  
Antonio

---

<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:** [August 4, 2023, 12:32pm UTC](https://community.sonarsource.com/t/c-false-positive-object-is-null-on-at-least-one-execution-path/95984/8 "2023-08-04T12:32:14Z")

</div>

Closed on August 4, 2023, 12:32pm UTC

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