Skip to content
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

Fix NullReferenceException when expanding property functions that return null #6414

Merged
merged 1 commit into from May 6, 2021

Conversation

ladipro
Copy link
Member

@ladipro ladipro commented May 5, 2021

Fixes #6413

Context

This is a regression introduced in #6128. MSBuild crashes when evaluating a project where a property function returns null and its result is concatenated with another non-empty value.

Changes Made

Add a null check.

Testing

Fixed and extended the relevant test case.

Notes

Enable "Hide whitespace changes" when reviewing this change.

Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and I agree that we should take this in 16.10. @marcpopMSFT, any objection? The regression was reported by 1ES.


Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(pg, FileSystems.Default);

string result = expander.ExpandIntoStringLeaveEscaped("$([System.Convert]::ChangeType(,$(SomeStuff.GetType())))", ExpanderOptions.ExpandProperties, MockElementLocation.Instance);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this just a fancy way to get null before, and you're using the easier approach now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not evaluating to null before so not hitting the intended code path. Presumably because the (, argument omission makes us pass an empty string.

Copy link
Member

@benvillalobos benvillalobos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me a sec to realize the "meat" of the change is just making sure propertyValue doesn't get added if null. LGTM

string result = expander.ExpandIntoStringLeaveEscaped("$([System.Convert]::ChangeType(,$(SomeStuff.GetType())))", ExpanderOptions.ExpandProperties, MockElementLocation.Instance);

// The null-returning function is the only thing in the expression.
string result = expander.ExpandIntoStringLeaveEscaped("$([System.Environment]::GetEnvironmentVariable(`_NonExistentVar`))", ExpanderOptions.ExpandProperties, MockElementLocation.Instance);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now reminded that if an environment var doesn't exist, GetEnvironmentVariable returns null.

@ladipro ladipro merged commit c040391 into dotnet:vs16.10 May 6, 2021
@ladipro ladipro deleted the 6413-fix-null-evaluation-fail branch May 6, 2021 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants