Skip to content

remove redundant null checks#7508

Open
SimonCropp wants to merge 1 commit intomicrosoft:mainfrom
SimonCropp:remove-redundant-null-checks
Open

remove redundant null checks#7508
SimonCropp wants to merge 1 commit intomicrosoft:mainfrom
SimonCropp:remove-redundant-null-checks

Conversation

@SimonCropp
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings March 8, 2026 12:03
Copy link
Contributor

Copilot AI left a comment

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 removes redundant null checks in several components across Microsoft.Testing.Platform, the VSTest bridge, the MSTest adapter platform services, and an analyzer code fix—aligning the code with existing nullability contracts and non-null field initializations.

Changes:

  • Removed dead null checks on fields that are always initialized (e.g., ConcurrentQueue, _properties dictionary).
  • Simplified conditional logic by relying on [NotNullWhen(true)] out-parameter contracts for command-line parsing.
  • Simplified Roslyn code-fix logic by removing a redundant ReturnType != null check.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Platform/Microsoft.Testing.Platform/Telemetry/TelemetryManager.cs Treats GetFolderPath(...) result as non-null and removes redundant guarding before Path.Combine.
src/Platform/Microsoft.Testing.Platform/Services/StopPoliciesService.cs Removes redundant _maxFailedTestsCallbacks is null guard (queue is always initialized).
src/Platform/Microsoft.Testing.Extensions.VSTestBridge/ObjectModel/ContextAdapterBase.cs Removes redundant filterExpressions is not null check, relying on the TryGetOptionArgumentList nullability contract.
src/Analyzers/MSTest.Analyzers.CodeFixes/TestMethodShouldBeValidCodeFix.cs Removes redundant null check for MethodDeclarationSyntax.ReturnType.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestContextImplementation.cs Removes redundant _properties == null guard (_properties is always constructed in the ctor).
src/Adapter/MSTestAdapter.PlatformServices/AssemblyResolver.cs Removes redundant null guard for a non-nullable List<RecursiveDirectoryPath> parameter.


ITestApplicationModuleInfo testApplicationModuleInfo = serviceProvider.GetTestApplicationModuleInfo();
#pragma warning disable RS0030 // Do not use banned APIs - There is no easy way to disable it for all members
string? directory = environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.Create);
Copy link
Member

@Youssef1313 Youssef1313 Mar 8, 2026

Choose a reason for hiding this comment

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

This one I'm not sure about. Some tests might be mocking stuff in a way that breaks this. If we can write the tests in a better way, that could be a good option. Otherwise, we probably keep this one for now.

But other than that, the rest of the changes look very good!

return false;
}

return _properties.TryGetValue(propertyName, out propertyValue);
Copy link
Member

Choose a reason for hiding this comment

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

error IDE0022: (NETCORE_ENGINEERING_TELEMETRY=Build) Use expression body for method

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