False positive on S4457

SonarAnalyzer.CSharp version 7.2.0.5463

This code is flagged with S4457:

if (activityName != null && string.IsNullOrWhiteSpace(activityName))
{
    throw new ArgumentException(nameof(activityName) + " is empty or white spaces.", nameof(activityName));
}

However, string.IsNullOrWhiteSpace(activityName) can be true regardless of activityName being null or not.

The intention of the test is to catch only the non-null empty or white space values.

Hi Paulo,

You have essentially the same problem that’s discussed in this ticket:
https://github.com/SonarSource/sonar-csharp/issues/1347#issuecomment-383104039

Please, read it for more information.

Kind regards,
Valeri

Hi @paulo.morgado,

I am a bit confused because you are mentioning S4457: Parameter validation in "async"/"await" methods should be wrapped and later on you are talking about whether activityName can be null which isn’t checked by this rule.

Could you let me know which problem you are facing?

Cheers,
Amaury

ping @paulo.morgado

Sorry! My bad!

It was S2583 and it seems to be solved 7.8.0.7320.

We haven’t changed the rule but I’m happy to hear that the problem is gone.