Skip to content

Conversation

@TravisEz13
Copy link
Member

Backport of #26291 to release/v7.6

Triggered by @TravisEz13 on behalf of @daxian-dbw

Original CL Label: CL-General

/cc @PowerShell/powershell-maintainers

Impact

REQUIRED: Choose either Tooling Impact or Customer Impact (or both). At least one checkbox must be selected.

Tooling Impact

  • Required tooling change
  • Optional tooling change (include reasoning)

Customer Impact

  • Customer reported
  • Found internally

Fixes #26277. Customers using the CompletionCompleters.CompleteFilename() API directly encounter NullReferenceException because the RelatedAsts value is null when calling this method directly. This is a regression affecting users who consume this public API programmatically.

Regression

REQUIRED: Check exactly one box.

  • Yes
  • No

Regression was introduced when the API started expecting RelatedAsts to be non-null, but this parameter is null when the API is called directly (not through tab completion pipeline).

Testing

Original PR added unit test in test/powershell/Host/TabCompletion/BugFix.Tests.ps1 that verifies the API handles null RelatedAsts value correctly. Backport verified by running the added test on release/v7.6 branch.

Risk

REQUIRED: Check exactly one box.

  • High
  • Medium
  • Low

Low risk. This is a targeted fix for a specific regression in the public API CompletionCompleters.CompleteFilename(). The fix adds a null check for the RelatedAsts parameter which was causing NullReferenceException when the API was called directly. The change is minimal (2 lines), well-tested, and only affects the error handling path of this specific API method.

Copilot AI review requested due to automatic review settings November 19, 2025 20:54
@TravisEz13 TravisEz13 added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 19, 2025
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 backports a fix for a regression in the public API CompletionCompleters.CompleteFilename() that causes a NullReferenceException when the API is called directly (not through the tab completion pipeline). The fix adds null-conditional operators to handle the case where RelatedAsts is null.

  • Adds null-safe access to context.RelatedAsts using the null-conditional operator (?.)
  • Includes a unit test that validates the API works correctly when called directly with an empty string
  • Low-risk, targeted fix for a specific regression affecting direct API consumers

Reviewed Changes

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

File Description
src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs Adds null-conditional operators to safely access context.RelatedAsts property, preventing NullReferenceException when the API is called directly
test/powershell/Host/TabCompletion/BugFix.Tests.ps1 Adds test case that validates CompleteFilename("") works without throwing NullReferenceException when called directly

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Review - Needed The PR is being reviewed label Nov 27, 2025
@microsoft-github-policy-service
Copy link
Contributor

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@adityapatwardhan adityapatwardhan merged commit dfa094e into PowerShell:release/v7.6 Dec 5, 2025
39 checks passed
@TravisEz13 TravisEz13 deleted the backport/release/v7.6/26291-38f988517 branch December 5, 2025 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Review - Needed The PR is being reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants