sonar-dotnet icon indicating copy to clipboard operation
sonar-dotnet copied to clipboard

Fix S2737 FP: Raised when exception filter is used.

Open jlaanstra opened this issue 1 year ago • 2 comments

Description

S2737 is raised in the following circumstance:

try
{
}
catch (Exception ex) when (LogException(ex))
{
    throw;
}

In this case LogException always returns false and therefore the catch should always be skipped but just in case the LogException function has a bug we place throw there.

Repro steps

See Description.

Expected behavior

No warnings for catch statement with exception filter.

Actual behavior

S2737 is raised for catch with exception filter.

Known workarounds

Suppression.

Related information

  • C#/VB.NET Plugins version
  • Visual Studio version
  • MSBuild / dotnet version
  • SonarScanner for .NET version (if used)
  • Operating System

jlaanstra avatar Oct 13 '23 23:10 jlaanstra

Thank you for reporting this issue. I wasn't aware that exception filters are called before the call stack is unwound, but this article explains quite well why it's a good idea to place exception logging into there. Confirmed as False Positive.

@zsolt-kolbay-sonarsource I see a commit associated with this issue, but it doesn't look like it's a fix. Any idea when this might get resolved?

jlaanstra avatar Feb 22 '24 20:02 jlaanstra