Repository navigation
Enable nullable for NuGet.Protocol plugin messages, logging, and contracts - #7434
Merged
Merged
Conversation
nkolev92
force-pushed
the
dev-nkolev92-nullableProtocolPluginMessages
branch
from
June 2, 2026 21:18
38170f0 to
b7f05bb
Compare
Co-authored-by: Copilot <[email protected]>
Removes `#nullable disable` from the plugin constants, exceptions,
event args, value objects, and interfaces in `NuGet.Protocol`.
Key behavioral annotations:
- `LineReadEventArgs.Line` becomes nullable; `StandardOutputReceiver`
already null-checks it.
- `ProtocolErrorEventArgs.Message` becomes nullable because the 1-arg
ctor never sets it.
- `PluginDiscoveryResult.Message` becomes nullable; returns null when
the plugin file is `Valid`.
- `PluginCreationResult.{Plugin, PluginMulticlientUtilities, Claims,
Message, Exception}` become nullable because the three ctors set
mutually exclusive subsets. An `internal bool IsSuccess` helper is
added with `[MemberNotNullWhen]` attributes so consumers can have
the compiler enforce the invariant.
- `IConnection.ProtocolVersion` becomes nullable per the doc comment.
- `IMessageDispatcher.SetConnection(IConnection?)` accepts null per
the doc comment.
- `IRequestHandlers.TryGet` out parameter uses
`[NotNullWhen(true)] out IRequestHandler?`.
- `PluginException`/`ProtocolException` ctors accept nullable
`message` and `innerException` to match `System.Exception` base.
Progress: NuGet/Home#14851
Co-authored-by: Copilot <[email protected]>
nkolev92
force-pushed
the
dev-nkolev92-nullableProtocolPluginMessages
branch
from
June 3, 2026 00:54
d9001ac to
f3fa223
Compare
After plugin contracts and message DTOs were annotated, `MessageConverter` (added in a parallel STJ-migration PR) failed to build on net472: - `MessageConverter.Read` pulls `requestId` from `JsonElement.GetString()` (returns `string?`) and validates it with `string.IsNullOrEmpty`. The net472 BCL reference assemblies do not have `[NotNullWhen(false)]` on `string.IsNullOrEmpty`, so the compiler still sees `string?` when the value is passed to `new Message(string requestId, ...)`. Added `!` suppression on the constructor call; the explicit guard above already throws on null/empty. - `MessageConverterTests.GetPayload<T>` returned `MessageUtilities.DeserializePayload<T>(message)` which is now `T?`. Added `!` so the helper keeps its non-null contract and callers don't need per-line suppressions. Co-authored-by: Copilot <[email protected]>
Nigusu-Allehu
approved these changes
Jun 4, 2026
Nigusu-Allehu
left a comment
Member
There was a problem hiding this comment.
LGTM bar a few questions I had
martinrrm
approved these changes
Jun 8, 2026
This was referenced Jun 8, 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
Completes the nullable enablement of the
NuGet.Protocolplugin layer: every type underNuGet.Protocol.Plugins/Messages/andNuGet.Protocol.Plugins/Logging/, plusMessageUtilitiesand the surrounding plugin contracts (interfaces, exceptions, event args, constants, and small value objects), is now annotated. The plugin runtime (Connection,Sender,Receiver,MessageDispatcher, request handlers, lifecycle, discovery, package operations) is intentionally left for a follow-up PR.Non-mechanical changes worth calling out:
PluginLogger.CreateStreamWriternow throws an explicitInvalidOperationExceptionif_logDirectoryPathis missing or ifProcess.MainModule?.FileNameis null, instead of relying on an implicitNullReferenceException.Message(string, MessageType, MessageMethod, JObject)constructor previously had an empty body, leavingRequestId,Type,Method, andPayloadObjectuninitialized. It now delegates to the internal constructor so the documented validation actually runs.PluginCreationResulthad five reference-type properties that are mutually exclusive depending on whether the creation succeeded. Added aninternal bool IsSuccessdiscriminator with[MemberNotNullWhen]attributes so the compiler enforces the documented contract: whenMessageis non-nullPlugin/PluginMulticlientUtilities/Claimsare null, and vice versa.LineReadEventArgs.LineandProtocolErrorEventArgs.Messageare now nullable to match the call sites that already produced null values (StandardOutputReceiver null-guards lines; the single-argumentProtocolErrorEventArgsconstructor never setsMessage).IConnection.ProtocolVersionandIMessageDispatcher.SetConnection's parameter are now nullable, matching what the XML docs already said.IRequestHandlers.TryGetis annotated with[NotNullWhen(true)]on theoutparameter so callers don't need a redundant null check after a successful lookup.message/innerExceptionparameters to match theSystem.Exceptionbase contract.PR Checklist