diff --git a/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.cs b/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.cs index 325c9cf52f5..7fd30194d2f 100644 --- a/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.cs +++ b/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Timers; +using System.Collections.Specialized; namespace Tests.Diagnostics { @@ -4310,3 +4311,20 @@ void Test(List aList) } } } + +// https://github.com/SonarSource/sonar-dotnet/issues/9580 +public class Repro_9580 +{ + public void IndexerReturnsNullInsteadOfThrowingException(NameValueCollection collection) + { + var element = collection["key"]; + if (element != null) + { + Console.WriteLine(element.ToString()); + } + if (collection.Count == 0) // Noncompliant - FP: the indexer with string argument returns null if the key is not found rather than throwing an exception, + { // so at this point we can't know for sure that the collection is not empty. + Console.WriteLine("Empty!"); // Secondary - FP + } + } +}