Skip to content

Conversation

@daxian-dbw
Copy link
Member

@daxian-dbw daxian-dbw commented Oct 23, 2025

PR Summary

Fix #26277

The RelatedAsts value is null when calling CompletionCompleters.CompleteFilename() directly. This PR fixes the code to handle that case.

PR Checklist

Copilot AI review requested due to automatic review settings October 23, 2025 18:36
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 fixes a null reference exception in the CompletionCompleters.CompleteFilename() API that occurs when RelatedAsts is null. The fix adds null-conditional operators to safely handle cases where the API is called directly without a completion context containing related ASTs.

  • Added null-conditional operators to prevent null reference exceptions when RelatedAsts is null
  • Added test coverage for calling CompleteFilename() directly with an empty string

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 Added null-conditional operators to safely access RelatedAsts and its elements
test/powershell/Host/TabCompletion/BugFix.Tests.ps1 Added test case to verify CompleteFilename() works when called directly without null reference exceptions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@daxian-dbw daxian-dbw added CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log BackPort-7.6.x-Consider labels Oct 23, 2025
@daxian-dbw daxian-dbw merged commit 38f9885 into PowerShell:master Oct 23, 2025
50 of 55 checks passed
@daxian-dbw daxian-dbw deleted the real_tab_fix branch October 23, 2025 23:19
@microsoft-github-policy-service
Copy link
Contributor

microsoft-github-policy-service bot commented Oct 23, 2025

📣 Hey @@daxian-dbw, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

TravisEz13 pushed a commit to TravisEz13/PowerShell that referenced this pull request Nov 19, 2025
SIRMARGIN pushed a commit to SIRMARGIN/PowerShell that referenced this pull request Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport-7.6.x-Migrated CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[System.Management.Automation.CompletionCompleters]::CompleteFilename("") throws NullReferenceException

2 participants