-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix NullReferenceException in tool install when package not found in manifest #52951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
1918794
c3841cb
9d67e02
0c4ffbf
14280f6
4921020
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,17 +102,15 @@ public override int Execute() | |
|
|
||
| private int ExecuteInstallCommand(PackageId packageId, VersionRange? versionRange) | ||
| { | ||
| FilePath manifestFile = GetManifestFilePath(); | ||
|
|
||
| (FilePath? manifestFileOptional, string warningMessage) = | ||
| _toolManifestFinder.ExplicitManifestOrFindManifestContainPackageId(_explicitManifestFile, packageId); | ||
| _toolManifestFinder.ExplicitManifestOrFindManifestContainPackageId(_explicitManifestFile, packageId, throwIfNoManifestFound: false); | ||
|
|
||
| if (warningMessage != null) | ||
| { | ||
| _reporter.WriteLine(warningMessage.Yellow()); | ||
|
||
| } | ||
|
|
||
| manifestFile = manifestFileOptional ?? GetManifestFilePath(); | ||
| FilePath manifestFile = manifestFileOptional ?? GetManifestFilePath(); | ||
| var existingPackageWithPackageId = _toolManifestFinder.Find(manifestFile).Where(p => p.PackageId.Equals(packageId)); | ||
|
|
||
| if (!existingPackageWithPackageId.Any()) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warningMessageis declared as non-nullable (string) in the tuple return type, but this method returnsnullfor it in several paths (explicit manifest, no match, and now the no-manifest catch). This makes the nullability contract incorrect for nullable-enabled callers and can lead to missed null checks / NRT warnings. Consider enabling nullable for this file (or at least for this method) and changing the signature to returnstring? warningMessage(and likewise acceptstring? explicitManifestFile).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the nullability annotations:
#nullable disablefrom ToolManifestFinderExtensions.cs(FilePath? filePath, string? warningMessage)string? explicitManifestFilestring?All tests pass (21 install + 9 uninstall).
Commit: 4921020