Skip to content

CA2000 false positives with out parameters #2245

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

Closed
jherby2k opened this issue Mar 27, 2019 · 1 comment
Closed

CA2000 false positives with out parameters #2245

jherby2k opened this issue Mar 27, 2019 · 1 comment
Assignees
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers Bug The product is not behaving according to its current intended design DataFlow Urgency-Soon

Comments

@jherby2k
Copy link

jherby2k commented Mar 27, 2019

Analyzer package

Microsoft.CodeAnalysis.FxCopAnalyzers

Package Version

v2.9.0

Diagnostic ID

CA2000

Repro steps

  1. Try to dispose a bunch of disposable objects from a concurrent queue:
while (Handles.TryDequeue(out var handle))
                handle.Dispose();

-or-

  1. Try to dispose a handle obtained via an out parameter using the IDisposable pattern
readonly CustomNativeHandle _handle;

internal TestConstructor()
{
    NativeMethods.GetHandle(out _handle);
}

public void Dispose()
{
    _handle.Dispose();
}

Expected behavior

No warning - both of these dispose of handles correctly, AFAICT. No warnings under last stable release.

Actual behavior

CA2000 warning

@mavasani mavasani self-assigned this Apr 15, 2019
@mavasani mavasani added Area-Microsoft.CodeAnalysis.NetAnalyzers Bug The product is not behaving according to its current intended design DataFlow Urgency-Soon labels Apr 15, 2019
mavasani added a commit to mavasani/roslyn-analyzers that referenced this issue Apr 16, 2019
mavasani added a commit to mavasani/roslyn-analyzers that referenced this issue Apr 16, 2019
…ons within conditional expression

We assume that out argument of an invocation returning false within a conditional branch is invalid and does not require disposing.

Fixes another scenario in dotnet#2245
@mavasani
Copy link
Contributor

Fixed with #2348

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers Bug The product is not behaving according to its current intended design DataFlow Urgency-Soon
Projects
None yet
Development

No branches or pull requests

2 participants