S2259: False positive "xy is null on at least one execution path."

That’s my code:

class AuthenticationService
{
    private AccessTokenModel _lastTokenModel;
    public DateTime? LastIssue { get; private set; }
    public async Task<string> GetAccessToken()
    {
        if (LastIssue + _lastTokenModel?.ExpiresIn > DateTime.Now)
            return _lastTokenModel.Token; // S2259: '_lastTokenModel' is null on at least one execution path.

Sonarcloud indicates

‘_lastTokenModel’ is null on at least one execution path.

That’s wrong!!!

Please stop propagating such false alerts. (It looks like you’re not familiar with the C#. We have a lot more false alerts! You’d better improve your issue detection otherwise we need to deactivate so many rules that Sonarcloud doesn’t make sense at all!)

Both :slight_smile:

The first is saying documentBase64 might be null and the second is warning that you are about to pass null to a method that doesn’t accept null.

2 Likes

Hey @aureole82

I’m marking this thread as unlisted for now – adding images with titles like “SonarCloud Sucks” is not in the spirit of this community

Be Civil

The topics discussed here matter to us, and we want you to act as if they matter to you, too. Be respectful of the topics and the people discussing them, even if you disagree with some of what is being said.

Your feedback is valuable to us, but it must also be respectful.

2 Likes

Hi Isak,
I did some more unit tests and: I’m really sorry! I am wrong and you’re absolutely right.

I didn’t read the second warning correctly…


and consider it as the opposite of Sonarcloud’s S2259 warning. I apologize for my rudeness and will check any future false-positives assumptions more carefully.

You did a great job!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.