False positive on S4457

csharp

(Paulo Morgado) #1

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.


(Valeri Hristov) #2

Hi Paulo,

You have essentially the same problem that’s discussed in this ticket:

Please, read it for more information.

Kind regards,
Valeri


(Amaury Levé) #3

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


(Amaury Levé) #4

ping @paulo.morgado


(Paulo Morgado) #5

Sorry! My bad!

It was S2583 and it seems to be solved 7.8.0.7320.


(Amaury Levé) #6

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