Skip to content

Prepare for nullable reference types in MICore#1595

Open
gregg-miskelly wants to merge 2 commits into
microsoft:mainfrom
gregg-miskelly:NullableRef_MICore
Open

Prepare for nullable reference types in MICore#1595
gregg-miskelly wants to merge 2 commits into
microsoft:mainfrom
gregg-miskelly:NullableRef_MICore

Conversation

@gregg-miskelly

@gregg-miskelly gregg-miskelly commented Jun 22, 2026

Copy link
Copy Markdown
Member

This PR contains work to prepare for enabling nullable reference types in MICore. Changes:

  • Correct two incorrect annotations in DebugEngineHost
  • Refactor MICommandFactory to use constructor injection (readonly _debugger field)
  • Move MICommandFactory.GetInstance() from DebuggedProcess to Debugger constructor
  • Fix bug: firstException should only be set when null (was checking != null)
  • Add null safety: _transport?.Close(), ThreadCreatedEvent?.Invoke, ThreadExitedEvent?.Invoke
  • Add null throw in SendToTransport for null transport
  • Use GetTargetProcessExitedReason() instead of raw _closeMessage
  • Null-safe access to _initialErrors/_initializationLog in OnDebuggerProcessExit
  • Pass EventArgs.Empty instead of null for DebuggerExitEvent
  • Use pattern matching for IsModuleLoad check
  • Make _commandLock readonly, initialize _lastCommandText

@gregg-miskelly gregg-miskelly requested a review from Copilot June 22, 2026 22:36
@gregg-miskelly gregg-miskelly changed the title Nullablitiy for MICore Enable nullable referenrce types in MICore Jun 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR enables nullable reference types (NRT) in the MICore layer of MIEngine and updates MICore code to compile cleanly under #nullable enable, primarily by annotating reference types, tightening null-handling, and consolidating helpers/usings.

Changes:

  • Enable NRT in MICore.csproj and add shared nullable attributes support.
  • Update MICore APIs/implementations with ?, null!, and improved null checks (including use of NullableHelpers string helpers).
  • Introduce GlobalUsings.cs to centralize common imports/aliases used across MICore.

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/MICore/Utilities.cs Annotates optional identifier and uses nullability-aware string helper.
src/MICore/UnixUtilities.cs Annotates nullable parameters/locals and updates whitespace/empty checks.
src/MICore/Transports/UnixShellPortTransport.cs Initializes non-null fields with null!, updates nullable parameters and output handling.
src/MICore/Transports/TcpTransport.cs Makes _client nullable, updates certificate callback nullability, and null-safe disposal.
src/MICore/Transports/StreamTransport.cs Adds NRT annotations to core transport fields/methods and null-safe writer disposal/reads.
src/MICore/Transports/ServerTransport.cs Makes patterns/prefix nullable and hardens GetDirectoryName usage.
src/MICore/Transports/RunInTerminalTransport.cs Annotates nullable streams/tasks and tightens path/env handling for NRT.
src/MICore/Transports/PipeTransport.cs Annotates process/streams/strings and adjusts async stream reading to handle null lines.
src/MICore/Transports/MockTransport.cs NRT annotations for fields/reads and minor debug output formatting update.
src/MICore/Transports/LocalTransport.cs Hardens GetDirectoryName and environment variable handling under NRT.
src/MICore/Transports/ITransport.cs Updates interface signatures for nullable waitLoop, exitCode, and command outputs.
src/MICore/Transports/ClientServerTransport.cs Propagates nullable waitLoop and nullable command outputs.
src/MICore/RunInTerminalLauncher.cs Removes direct System.Diagnostics using (relies on centralized usings/aliases).
src/MICore/ProcessMonitor.cs Makes timer/event nullable-aware and updates callback signatures.
src/MICore/PlatformUtilities.cs Reworks diagnostics dependency via explicit type aliasing and NRT string checks.
src/MICore/MIResults.cs Adds NRT annotations and refactors parsing flow/error reporting for NRT.
src/MICore/MIException.cs Updates whitespace checks and makes cached message nullable.
src/MICore/MICore.csproj Enables <Nullable>enable</Nullable> and links shared nullable attributes file.
src/MICore/Logger.cs Makes host log channels nullable and adjusts logging helpers for NRT.
src/MICore/LaunchOptions.cs Broad NRT annotations and additional null checks in JSON/XML option parsing.
src/MICore/LaunchCommand.cs Annotates optional handlers/description and simplifies description fallback.
src/MICore/JsonLaunchOptions.cs Annotates many DTO properties and converter methods for nullable JSON values.
src/MICore/IncludeExcludeList.cs Initializes lazy fields eagerly and updates empty checks under NRT.
src/MICore/GlobalUsings.cs Adds global static import for nullable helpers and central aliasing.
src/MICore/ExceptionHelper.cs Ensures stack traces are non-null when logging under NRT.
src/MICore/DebuggerDisposedException.cs Annotates optional fields/parameters for disposal exception scenarios.
src/MICore/Debugger.cs Updates event nullability, null-handling, and other NRT-related refactors.
src/MICore/CommandLock.cs Annotates nullable fields and improves assert-based flow assumptions.
src/MICore/CommandFactories/MICommandFactory.cs NRT annotations across factory surface and parsing helpers.
src/MICore/CommandFactories/lldb.cs NRT updates and avoids returning null collections.
src/MICore/CommandFactories/gdb.cs NRT updates for lock token and line parsing.
src/MICore/Checksum.cs NRT updates for cached string and byte storage initialization.

Comment thread src/MICore/GlobalUsings.cs Outdated
Comment thread src/MICore/LaunchOptions.cs Outdated
Comment thread src/MICore/LaunchOptions.cs
Comment thread src/MICore/MIResults.cs Outdated
@gregg-miskelly gregg-miskelly force-pushed the NullableRef_MICore branch 3 times, most recently from 4d6e35d to b540e23 Compare June 24, 2026 16:47
@gregg-miskelly gregg-miskelly changed the title Enable nullable referenrce types in MICore Null reference type fixes for MICore Jun 26, 2026
- Refactor MICommandFactory to use constructor injection (readonly _debugger field)
- Move MICommandFactory.GetInstance() from DebuggedProcess to Debugger constructor
- Fix bug: firstException should only be set when null (was checking != null)
- Add null safety: _transport?.Close(), ThreadCreatedEvent?.Invoke, ThreadExitedEvent?.Invoke
- Add null throw in SendToTransport for null transport
- Use GetTargetProcessExitedReason() instead of raw _closeMessage
- Null-safe access to _initialErrors/_initializationLog in OnDebuggerProcessExit
- Pass EventArgs.Empty instead of null for DebuggerExitEvent
- Use pattern matching for IsModuleLoad check
- Make _commandLock readonly, initialize _lastCommandText

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Comment thread src/DebugEngineHost.Common/HostLogChannel.cs
Comment thread src/MICore/Debugger.cs
@gregg-miskelly gregg-miskelly marked this pull request as ready for review June 26, 2026 00:49
@gregg-miskelly gregg-miskelly changed the title Null reference type fixes for MICore Prepare for nullable reference types in MICore Jun 26, 2026
Comment thread src/MICore/Debugger.cs
@@ -124,12 +124,12 @@ public StoppingEventArgs(Results results, BreakRequest asyncRequest = BreakReque
}

private ITransport _transport;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are changes for _transport? but we are not declaring it as ITransport??

Comment thread src/MICore/Debugger.cs
private void SendToTransport(string cmd)
{
_transport.Send(cmd);
ITransport transport = _transport ?? throw new InvalidOperationException();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this going to cause a crash if we get called via PostCommand?

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.

3 participants