-
Notifications
You must be signed in to change notification settings - Fork 484
Closed
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzersBugThe product is not behaving according to its current intended designThe product is not behaving according to its current intended designDataFlowFalse_PositiveA diagnostic is reported for non-problematic caseA diagnostic is reported for non-problematic casehelp wantedThe issue is up-for-grabs, and can be claimed by commentingThe issue is up-for-grabs, and can be claimed by commenting
Milestone
Description
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Describe the bug
var item = new ItemData(scannedFileName: filePath);
return parseChannel.Writer.WriteAsync(item);
The class ItemData is indeed IDisposable and WriteAsync can throw, so yep I would an IDisposable error, which there is.
Changing to:
So, to address the issue I change that to this.
var item = new ItemData(scannedFileName: filePath);
try
{
var parseTask = parseChannel.Writer.WriteAsync(item);
item = null;
return parseTask;
}
finally
{
item?.Dispose();
}
Only results in:
Severity | Code | Description | Project | File | Line | Suppression State | Tool |
---|---|---|---|---|---|---|---|
Warning | CA1508 | 'item' is always 'null'. Remove or refactor the condition(s) to avoid dead code. | ItemCheck | ... | 636 | Active | Microsoft.CodeAnalysis.NetAnalyzers |
Severity | Code | Description | Project | File | Line | Suppression State | Tool |
---|---|---|---|---|---|---|---|
Warning | CA2000 | Call System.IDisposable.Dispose on object created by 'new ItemData(scannedFileName: filePath)' before all references to it are out of scope | ItemCheck | ... | 627 | Active | Microsoft.CodeAnalysis.NetAnalyzers |
N-Olbert
Metadata
Metadata
Assignees
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzersBugThe product is not behaving according to its current intended designThe product is not behaving according to its current intended designDataFlowFalse_PositiveA diagnostic is reported for non-problematic caseA diagnostic is reported for non-problematic casehelp wantedThe issue is up-for-grabs, and can be claimed by commentingThe issue is up-for-grabs, and can be claimed by commenting