Skip to content

Add CA2025 regression coverage for tuple-state task races - #56938

Open
nagilson with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-ca2025-null-reference-exception
Open

nagilson with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-ca2025-null-reference-exception

Conversation

Copilot AI commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: b5ab0d961785ed40448538269d9b39eaa5da93f4

Dimension Assessment Rationale
Change confidence 9/10 ↑ Test-only diff vs main (one test file, +68 lines); no analyzer behavior change.
↑ All 20 DoNotPassDisposablesIntoUnawaitedTasksTests pass locally after merging current main.
↑ New test fails with the exact AD0001 NullReferenceException when the main-branch fix (aa287a97031) is locally reverted, so it guards the regression.
↓ Fresh CI for this head is pending; earlier run failures (NU1903 in Microsoft.DotNet.Cli.Run.Tests for vulnerable Microsoft.DotNet.ILCompiler 11.0.0-preview.7.26381.103) were unrelated and main has since moved to 11.0.0-rc.3.26522.148; the old AzDO build was purged, so not all earlier failures could be inspected.

CA2025 could crash when non-local disposable expressions appeared alongside tuple state, competing tasks, Task.WhenAny, and later foreach disposal.

  • Regression coverage
    • Adds the reported operation-tree shape using Task.Factory.StartNew.
    • Verifies the existing non-local argument filtering handles calls such as:
var connecting = ConnectAsync(writer.AsStream(), reader.AsStream());

if (await Task.WhenAny(connecting, server) == server)
{
    await server;
}

foreach (var stream in streams)
{
    stream.Dispose();
}
  • Scope
    • No analyzer behavior changes; this guards the existing null-reference fix against the additional trigger shape.
    • This PR adds coverage for the analyzer fix already on main. It does not include the .NET 10 (10.0.4xx) servicing fix requested in the issue; release/10.0.4xx still contains the unsafe disposableArg.Local access.

@azure-pipelines

azure-pipelines Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
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.

Co-authored-by: nagilson <23152278+nagilson@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CA2025 analyzer crash with NRE during compilation Add CA2025 regression coverage for tuple-state task races Nov 5, 2026
Copilot AI requested a review from nagilson November 5, 2026 01:16
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@Evangelink
Evangelink marked this pull request as ready for review November 25, 2026 10:12
@Evangelink
Evangelink requested a review from a team as a code owner November 25, 2026 10:12
Copilot AI balanced review requested due to automatic review settings November 25, 2026 10:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the regression-test and cancellation-token changes.

No open issues 🎉

What changed in this PR

Adds regression coverage for the CA2025 analyzer crash scenario reported in #56540, guarding the existing fix without changing analyzer behavior or adding the .NET 10 servicing fix.

Changes:

  • Adds a no-diagnostic test combining tuple-state Task.Factory.StartNew, non-local disposable arguments, Task.WhenAny, and subsequent foreach disposal.
  • Adds TestContext to pass the test cancellation token to the analyzer test harness.
File Description
src/​Microsoft.CodeAnalysis.NetAnalyzers/​tests/​Microsoft.CodeAnalysis.NetAnalyzers.UnitTests/​Microsoft.CodeQuality.Analyzers/​QualityGuidelines/​DoNotPassDisposablesIntoUnawaitedTasksTests.cs Adds the tuple-state task-race regression test and cancellation-token support.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CA2025 analyzer still crashes with NRE (AD0001) on 10.0.4xx GA — trigger shape not covered by #53926

4 participants