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

Rule S3966: FP when using StreamWriter #3644

Closed
costin-zaharia-sonarsource opened this issue Oct 6, 2020 · 0 comments · Fixed by #3647
Closed

Rule S3966: FP when using StreamWriter #3644

costin-zaharia-sonarsource opened this issue Oct 6, 2020 · 0 comments · Fixed by #3647
Assignees
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@costin-zaharia-sonarsource
Copy link
Member

costin-zaharia-sonarsource commented Oct 6, 2020

Description

StreamWriter is closing and not disposing the underling stream. See: https://github.com/microsoft/referencesource/blob/master/mscorlib/system/io/streamwriter.cs#L269

Rule description needs to be updated too since it's based on this FP.

Source: #209 (comment)

Repro steps

using (Stream stream = new FileStream("file.txt", FileMode.OpenOrCreate))
{
    using (StreamWriter writer = new StreamWriter(stream))  // Noncompliant: 'stream' will be disposed twice
    {
        // Use the writer object...
    }
}

Expected behavior

There should be no diagnostic raised for stream in this case since it is not disposed twice.

Actual behavior

A FP is raised reporting that the stream was disposed twice.

Known workarounds

None.

Related information

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

Successfully merging a pull request may close this issue.

2 participants