From 2bd1cb4f3ce72cee0705e494df1ec007d2a52f88 Mon Sep 17 00:00:00 2001 From: Pavel Mikula Date: Tue, 25 Oct 2022 08:54:47 +0200 Subject: [PATCH] S2259: Add FP repro for #6241 --- .../Roslyn/NullPointerDereference.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/NullPointerDereference.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/NullPointerDereference.cs index 7c50d7312bd..6da6d763074 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/NullPointerDereference.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/NullPointerDereference.cs @@ -1703,3 +1703,33 @@ public void StringIsNullOrEmpty(string value) } } } + +// https://github.com/SonarSource/sonar-dotnet/issues/6241 +public class Repro_6241 +{ + public void WithGenericValue() + { + HashSet value = null; + if (value is null) + { + value.ToString(); // FN + } + else + { + value.ToString(); // Noncompliant FP + } + } + + public void WithNormalValue(List inputs) + { + HashSet value = null; + if (value is null) + { + value.ToString(); // Noncompliant + } + else + { + value.ToString(); // Compliant + } + } +}