github / github/codeql

LGTM.com - false positive: null-check in LINQ Query Syntax causes inference of possible null value

Ouverte
#6,512 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
acknowledged C# false-positive not security
Langage dominant
CodeQL
Étoiles
10.1k
Forks
2.1k
Merge moyen
2 j 15 h
PR mergées (30 j)
141

Description

**Description of the false positive**

Here is my example query. Null checks in LINQ query syntax should infer that the next access of the checked variable is not null, but instead it is the very null check that causes an LGTM warning.

```csharp
var x = from seed in seedsToTrim
let parent = context[seed.Parent]
where parent?.Content.Type == "search_title"
let title = context.GetChildren(seed).FirstOrDefault(s => s.Content.Type == "title")
where title != null // null check here should infer that title is not null in the next line
let r = title.Content.Value // but previous check causes LGTM: 'Variable title may be null here as suggested by this null check.'
let distance = this.Comparator.Distance(r.NormalizeTitle(), parent?.Content.Value.NormalizeTitle())
orderby distance ascending, context.GetChildren(seed).Count() descending
select seed
```
https://lgtm.com/projects/g/SnowflakePowered/snowflake/snapshot/91c41ebda631e445ba26d521696adb2537a720da/files/src/Snowflake.Support.Scraping.Primitives/ResultCuller.cs?sort=name&dir=ASC&mode=heatmap#x47f6f70265861613:1

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.