Enable nullable annotations for NuGet.Protocol service index, repository signature, and registration types#7481
Merged
Conversation
martinrrm
approved these changes
Jun 17, 2026
This was referenced Jun 19, 2026
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.
Bug
Progress: NuGet/Home#14851
Description
Enable nullable annotations for NuGet.Protocol Phase 15 (Service index / repository signature resources) and Phase 16 (Search model leaves — registration types + vulnerability metadata).
Files annotated (removed
#nullable disable):Phase 15 — Public resource types + providers:
ServiceIndexResourceV3.cs— service index resource with JObject and STJ code pathsServiceIndexResourceV3Provider.cs— caching provider with retry logicRepositorySignatureResource.cs— repository signing resourceRepositorySignatureResourceProvider.cs— provider with dual STJ/NSJ deserializationPhase 16 — Internal registration DTOs + public vulnerability metadata:
RegistrationIndex.cs,RegistrationPage.cs,RegistrationLeafItem.cs— internal JSON DTOsPackageVulnerabilityMetadata.cs— public vulnerability modelKey decisions:
GetServiceEntryUrireturnsUri?—FirstOrDefault()can genuinely return null when no matching service type is registered. Callers that need non-null use?? throw.httpSourceResourcenull checks withInvalidOperationException— Instead of suppressing with!, both providers now throw explicitly ifGetResourceAsync<HttpSourceResource>()returns null. This is a coding error (misconfigured source), not a user error, so inline interpolated strings are used (same pattern asVulnerabilityInfoResourceV3). No shared resx string needed.RepositorySignatureResourceProviderdeserialization null checks —JsonSerializer.DeserializeAsyncreturnsT?. Instead ofmodel!, we use?? throw new FatalProtocolException(...)to give a clear error at the deserialization boundary rather than an NRE later.RegistrationPageproperties (Url,Lower,Upper) annotated non-null — The protocol spec guarantees these. Existing code already uses them without null checks (NuGetVersion.Parse(page.Lower)).Itemsstays nullable per its documented semantics.NULL_INCcomment added to document the= null!initializers.PackageVulnerabilityMetadata.AdvisoryUrlannotated non-null — The protocol spec guaranteesadvisoryUrlis always present. Using= null!with a doc comment linking to the spec. This avoids forcing callers to add unnecessary!or null checks.RepositorySignatureResourceinternal ctor — Added_ = model ?? throwand_ = source ?? throwguard clauses. Without annotation, callers would NRE onmodel.AllRepositorySignedwith no useful diagnostics. Explicit throws give clear failure messages.ServiceIndexResourceV3ctors — Same pattern:_ = index ?? throwand_ = model ?? throwsince the public ctor delegates to internal and external callers could pass null.PR Checklist