-
Notifications
You must be signed in to change notification settings - Fork 231
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 FP: Lifted operator results in null value in value type comparison #4250
Comments
This is originally created by me here: https://community.sonarsource.com/t/s2259-false-positive-xy-is-null-on-at-least-one-execution-path/41172 |
Hi @aureole82, Can you please provide more explanation why do you think that it's a False Positive? // This is usage of lifted operator that you've send a link to.
// That makes this + operator and IF condition save and so issue is raised on this line.
// Usage of _lastTokenModel? explicitly states, that you expect _lastTokenModel to be null at this line sometimes.
if (LastIssue + _lastTokenModel?.ExpiresIn > DateTime.Now)
// At this line _lastTokenModel could be null. You explicitly expect it to be null sometimes.
// So _lastTokenModel.Token can lead to null reference exception as I see it.
return _lastTokenModel.Token; This looks like a True Positive to me. |
Please state a setting where the |
Ah, ok. Now I see it. So it's based on fact that That's a tricky chain of constraints. But I can confirm it as a False Positive now. |
Related C# spec documents for lifting and null handling by operators: See also #5918 (comment) for where to add this logic. |
Related to nullable => MMF-2401 => demilestoning for now |
We investigated the control flow graph with the following results: if (arg?.Length == 0)
{
Tag(""If"", arg);
}
else
{
Tag(""Else"", arg);
}
The work on (the upcoming) MMF-2401 will be based on this. |
ToDo:
|
Repro steps
Expected behavior
No complaints because: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/nullable-value-types#lifted-operators
Actual behavior
Related information
The text was updated successfully, but these errors were encountered: