github / github/codeql

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

Aberta
#6,512 2 comentários 0 reações 0 responsáveis Ver no GitHub
acknowledged C# false-positive not security
Linguagem predominante
CodeQL
Estrelas
10.1k
Forks
2.1k
Merge médio
2d 15h
PRs com merge (30d)
141

Descrição

**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

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.