[release/v7.6] Fix a regression in the API CompletionCompleters.CompleteFilename() that causes null reference exception
#26487
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.