False positive on S4457

SonarAnalyzer.CSharp version

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:

Please, read it for more information.

Kind regards,

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?


ping @paulo.morgado

Sorry! My bad!

It was S2583 and it seems to be solved

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