github / github/codeql

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

未關閉
#6,512 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
acknowledged C# false-positive not security
主要語言
CodeQL
星號
10.1k
分支
2.1k
平均合併
2 天 15 小時
30 天內合併 PR
141

描述

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

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。