Skip to content

NET-1772 S3966: Raise issue on different location for using statements. #7358

Closed
@mary-georgiou-sonarsource

Description

Requires MMF-2568 to be implementable.

S3966 currently covers two main categories of double disposal.
1.

    public void DisposedTwice()
   {
       var d = new Disposable();
       d.Dispose();
       d.Dispose(); // Noncompliant {{Resource 'd' has already been disposed explicitly or implicitly through a using statement. Please remove the redundant disposal.}}
   }
  public void Disposed_UsingStatement()
  {
      using (var d = new Disposable()) // Noncompliant {{Resource 'd = new Disposable()' has already been disposed explicitly or implicitly through a using statement. Please remove the redundant disposal.}}
      {
          d.Dispose();
      }
  }

The issue would be clearer for the user if in the case of Using statement, we'd raise in d.Dispose (as primary or secondary location).

Metadata

Metadata

Assignees

No one assigned

    Labels

    UXImprove any kind of user experience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions