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 S2953 FP: Implement IDisposable.Dispose on extension methods static class #9679

Closed
manfred-brands opened this issue Oct 7, 2024 · 2 comments
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.

Comments

@manfred-brands
Copy link

Description

S2953 raised a false positive on a static class.

Repro steps

We have an extension method on Lazy to dispose it, but only if the value was created.

    public static class DisposableExtensions
    {
        public static void Dispose<T>(this Lazy<T> lazy)
            where T : class, IDisposable
        {
            if (lazy.IsValueCreated)
            {
                lazy.Value.Dispose();
            }
        }
    }

Expected behavior

S2953 is not raised.

Actual behavior

S2953 is raised.

Known workarounds

Suppress

Related information

  • C#/VB.NET Plugins version: 9.32.0.97167
  • Visual Studio version: 17.11.4
  • MSBuild / dotnet version: 8.0.402
  • SonarScanner for .NET version (if used)
  • Operating System: Win10 22H2
@CristianAmbrosini CristianAmbrosini changed the title Fix S2953 FP/FN: Implement IDisposable.Dispose on extension methods static class Fix S2953 FP: Implement IDisposable.Dispose on extension methods static class Oct 7, 2024
@CristianAmbrosini CristianAmbrosini self-assigned this Oct 7, 2024
@CristianAmbrosini
Copy link
Contributor

Hi @manfred-brands!
I confirm this as a FP.
I already added the reproducer and fixed the issue; it was a low-hanging fruit.
You will not experience it anymore starting from the next release, enjoy!

@CristianAmbrosini CristianAmbrosini added Type: False Positive Rule IS triggered when it shouldn't be. Area: C# C# rules related issues. labels Oct 7, 2024
@CristianAmbrosini CristianAmbrosini removed their assignment Oct 7, 2024
@manfred-brands
Copy link
Author

@CristianAmbrosini Thanks, but I don't see neither a PR or changes to master with a fix so how can this be closed?
Did you forgot to push your changes?

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. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

2 participants