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

Improve S2222: Expect operations to throw outside try statement #5806

Open
pavel-mikula-sonarsource opened this issue Jul 1, 2022 · 0 comments
Labels
Area: C# C# rules related issues. Area: CFG/SE CFG and SE related issues. Area: VB.NET VB.NET rules related issues. Type: SE Improve SE engine

Comments

@pavel-mikula-sonarsource
Copy link
Contributor

Description

Expect operations to throw exception also outside try statement.

Monitor.Enter(obj);  // Noncompliant
SomethingThatCanThrow();
Monitor.Exit(obj);

How

Implementation is easy

           if (exceptionCandidate.FromOperation(node.Operation) is { } exception)
            {
                foreach (var successor in ExceptionSuccessors(node, exception, node.Block.EnclosingRegion(ControlFlowRegionKind.Try)))

The affect on our test framework is big. As a prerequisite, we need to change the way Tag("") asserting works.

Change is scaffolded in a branch https://github.com/SonarSource/sonar-dotnet/tree/Pavel/SE-ExceptionsOutsideTry but many UTs needs polishing to make it run. The test framework update should be done in few PRs as a prerequisite:

  • Extend the functionality and migrate some test case
  • Migrate all usages
  • Implement this ticket
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: CFG/SE CFG and SE related issues. Area: VB.NET VB.NET rules related issues. Type: SE Improve SE engine
Projects
None yet
Development

No branches or pull requests

1 participant