Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S2737 FP: Raised when exception filter is used #8199

Closed
jlaanstra opened this issue Oct 13, 2023 · 2 comments · Fixed by #9385
Closed

Fix S2737 FP: Raised when exception filter is used #8199

jlaanstra opened this issue Oct 13, 2023 · 2 comments · Fixed by #9385
Assignees
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@jlaanstra
Copy link

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
@mary-georgiou-sonarsource mary-georgiou-sonarsource changed the title Fix S2737 FP/FN: Raised when exception filter is used. Fix S2737 FP: Raised when exception filter is used. Oct 16, 2023
@zsolt-kolbay-sonarsource
Copy link
Contributor

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 zsolt-kolbay-sonarsource added Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be. Area: VB.NET VB.NET rules related issues. labels Oct 16, 2023
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource removed their assignment Oct 16, 2023
@jlaanstra
Copy link
Author

@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?

@pavel-mikula-sonarsource pavel-mikula-sonarsource added this to the 9.27 milestone Jun 4, 2024
@pavel-mikula-sonarsource pavel-mikula-sonarsource changed the title Fix S2737 FP: Raised when exception filter is used. Fix S2737 FP: Raised when exception filter is used Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants