Repository navigation
Conversation
Keep existing disposal state when a helper first references a field instead of reinitializing it as undisposed. Add regression coverage for nullable-enabled native Lock and Monitor call chains, including missing-disposal controls. Fixes dotnet#57136
|
Azure Pipelines: Successfully started running 1 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Author
|
If you accept change, it will be great to propagate also to .NET11 and .NET10. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change preserving disposal state during helper-field discovery.
No open issues 🎉
What changed in this PR
Addresses #57136, a CA2213 false positive when a disposable field is disposed before a helper call involving System.Threading.Lock. The shared disposal analysis now preserves existing location state instead of resetting it when discovering a field in a helper.
Changes:
- Initialize disposal state only for previously untracked locations.
- Add four nullable-enabled regression cases covering
System.Threading.Lockandobjectgates, with controls verifying that missing disposal still reports CA2213.
| File | Description |
|---|---|
| src/Microsoft.CodeAnalysis.NetAnalyzers/tests/Microsoft.CodeAnalysis.NetAnalyzers.UnitTests/Microsoft.NetCore.Analyzers/Runtime/DisposableFieldsShouldBeDisposedTests.cs | Adds parameterized regression coverage for disposal before helper calls within try/finally. |
| src/Microsoft.CodeAnalysis.NetAnalyzers/src/Utilities/FlowAnalysis/FlowAnalysis/Analysis/DisposeAnalysis/DisposeAnalysis.DisposeDataFlowOperationVisitor.cs | Preserves existing disposal state during helper field discovery. |
Review effort: Balanced
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #57136.
CA2213 can report a field as undisposed even when its
Dispose()method is called unconditionally before a helper call involvingSystem.Threading.Lock.When analyzing the helper, the first field reference reinitializes its disposal state, overwriting the caller’s
Disposedstate. Preserve existing analysis state and initialize only previously untracked locations.Adds four regression cases covering nullable-enabled code with
System.Threading.Lockandobjectgates, including controls that verify missing disposal still produces CA2213.Testing