Skip to content

NuGet.Protocol nullability v2 - #7285

Merged
nkolev92 merged 6 commits into
devfrom
dev-nkolev92-protocol2
Apr 28, 2026
Merged

nkolev92 merged 6 commits into
devfrom
dev-nkolev92-protocol2

Conversation

@nkolev92

@nkolev92 nkolev92 commented Apr 15, 2026 •

Copy link
Copy Markdown
Member

Bug

Progress: NuGet/Home#14851

Description

Continues the NuGet.Protocol nullable annotation work. Removes #nullable disable from 8 more files and annotates public API surfaces.

Files migrated

  • HttpSourceCacheContext.cs – RootTempFolder made string?
  • NullSourceCacheContext.cs – fixed WithRefreshCacheTrue()/Clone() to use Instance property instead of _instance field (avoids returning null before first access)
  • PackageDownloadContext.cs – DirectDownloadDirectory, ClientPolicyContext, PackageSourceMapping made nullable; directDownloadDirectory and packageSourceMappingConfiguration parameters made nullable
  • RemoteSourceDependencyInfo.cs – annotated as non-null; contentUri marked with NULL_INC (no runtime check added — see note below); fixed Equals(object) which was incorrectly casting to PackageDependencyInfo instead of RemoteSourceDependencyInfo
  • SourceCacheContext.cs – Clone() now assigns _generatedTempFolder via field instead of through the GeneratedTempFolder property (which has side effects); Dispose uses captured local
  • SourcePackageDependencyInfo.cs – Source, DownloadUri, PackageHash made nullable (all optional per XML docs)
  • UserAgent.cs – removed #nullable disable (no annotation changes needed)
  • UserAgentStringBuilder.cs – _vsInfo, _osInfo, _ciInfo fields and WithVisualStudioSKU parameter made nullable

NULL_INC note

RemoteSourceDependencyInfo.ContentUri is annotated as non-null (string!) in the public API, but no runtime ArgumentNullException guard is added in the constructor. This property maps to the packageContent field in the NuGet V3 registration API, which is required by protocol — so null is not expected in practice. However, since the previous code silently accepted null and we lack telemetry to be certain no caller passes it, a runtime throw is deferred. The property carries a NULL_INC XML remark to track this.

Bug fix

RemoteSourceDependencyInfo.Equals(object) was casting to PackageDependencyInfo instead of RemoteSourceDependencyInfo, meaning it always returned false for valid comparisons.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@dotnet-policy-service dotnet-policy-service Bot added Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed and removed Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed labels Apr 22, 2026
nkolev92 and others added 4 commits April 24, 2026 18:16
…NC remark

Remove the newly-added ArgumentNullException guard for contentUri to avoid
introducing a new throw in a previously-permissive code path. The non-null
annotation is kept but marked with NULL_INC for future telemetry-guided follow-up.

Co-authored-by: Copilot <[email protected]>
Covers annotation philosophy (non-null bias), PublicAPI.Shipped.txt update
rules, NULL_INC escape hatch criteria, and step-by-step migration workflow.

Co-authored-by: Copilot <[email protected]>
ContentUri maps to the required packageContent field in the NuGet V3
registration API, so null is not expected in practice.

Co-authored-by: Copilot <[email protected]>
@nkolev92
nkolev92 force-pushed the dev-nkolev92-protocol2 branch from 264bd08 to 39a08fd Compare April 25, 2026 01:16
@nkolev92
nkolev92 marked this pull request as ready for review April 25, 2026 01:16
@nkolev92
nkolev92 requested a review from a team as a code owner April 25, 2026 01:16
@nkolev92
nkolev92 requested review from jeffkl and kartheekp-ms April 25, 2026 01:16
nkolev92 and others added 2 commits April 24, 2026 18:27
Add null-forgiving operator on DownloadUri access in test assertions where
the value is known non-null from the test setup.

Co-authored-by: Copilot <[email protected]>
…stead of null

The dependencies parameter is non-null after nullable enablement. These tests
don't use dependencies, so Enumerable.Empty<PackageDependency>() is correct.

Co-authored-by: Copilot <[email protected]>
@nkolev92
nkolev92 merged commit a456ec0 into dev Apr 28, 2026
17 of 18 checks passed
@nkolev92
nkolev92 deleted the dev-nkolev92-protocol2 branch April 28, 2026 00:58
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.

2 participants