[release/v7.6] Fix a regression in the API CompletionCompleters.CompleteFilename() that causes null reference exception#26487
Merged
adityapatwardhan merged 1 commit intoPowerShell:release/v7.6from Dec 5, 2025
Conversation
… that causes null reference exception (PowerShell#26291)
Contributor
There was a problem hiding this comment.
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.RelatedAstsusing 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.
iSazonov
approved these changes
Nov 20, 2025
Contributor
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
12 tasks
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.
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
Customer Impact
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.
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.
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.