S2583 false positive when using IsNullOrWhitespace after a null check

54 views
Skip to first unread message

pers...@paulhickman.co.uk

unread,
Jun 7, 2018, 7:29:08 AM6/7/18
to SonarLint
Using SonarAnalyzer.CSharp 7.2.0.5463, the call to string.IsNullOrWhiteSpace below erroneously generates warning S2583 stating the code will not be executed because it always returns false.

void Func(string arg)
{
  if (arg== null)
  {
    throw new ArgumentNullException(nameof(arg));
  }

  if (string.IsNullOrWhiteSpace(arg))
  {
     throw new ArgumentException("is blank", nameof(arg));
  }
}

valeri....@sonarsource.com

unread,
Jun 8, 2018, 4:32:31 AM6/8/18
to SonarLint
Hi,

This problem was raised a few days ago in the following comment: https://github.com/SonarSource/sonar-csharp/issues/1347#issuecomment-392527036, you could find explanation why it happens there.

Kind regards,
Valeri
Reply all
Reply to author
Forward
0 new messages