Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S2259: Add FP repro for #4537 #4600

Merged
merged 1 commit into from
Jul 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -819,5 +819,19 @@ string DoSomethingArg(IEnumerable<object> list)
return item.ToString(); // False Negative, item could be null here
}
}

// https://github.com/SonarSource/sonar-dotnet/issues/4537
class Repro_4537
{
private void ConditionalAccess_NullCoalescing()
{
string someString = null;

if (!someString?.Contains("a") ?? true)
Console.WriteLine("It's null or doesn't contain 'a'");
else
Console.WriteLine(someString.Length); // Noncompliant FP, this path is unreachable
pavel-mikula-sonarsource marked this conversation as resolved.
Show resolved Hide resolved
}
}
}