Skip to content

Add null check for textSnapshot#24693

Merged
jinujoseph merged 3 commits intodotnet:dev15.6.xfrom
chborl:unexpectednull_156
Feb 14, 2018
Merged

Add null check for textSnapshot#24693
jinujoseph merged 3 commits intodotnet:dev15.6.xfrom
chborl:unexpectednull_156

Conversation

@chborl
Copy link
Copy Markdown
Contributor

@chborl chborl commented Feb 7, 2018

Fixes #7364

Customer scenario

In some situations, when customer renames a variable an Unexpected null dialog appears and the rename feature is broken until VS is restarted.

Bugs this fixes

#7364

Workarounds, if any

Restart VS and try again.

Risk

Very low, just added a null check

Performance impact

None

Is this a regression from a previous update?

No

Root cause analysis

This code did not originally have a null check, but in looking at other uses of the same method it appears a null check is standard. Unable to add a test for this because it can't be predictably reproduced.

How was the bug found?

Customers and internal users

Test documentation updated?

n/a

@chborl chborl requested a review from a team as a code owner February 7, 2018 19:07
@chborl
Copy link
Copy Markdown
Contributor Author

chborl commented Feb 7, 2018

@CyrusNajmabadi @sharwell @dpoeschl , for review please. Any reason a null check wouldn't be a good idea here?

@chborl
Copy link
Copy Markdown
Contributor Author

chborl commented Feb 7, 2018

See #7566 for discussion of why to check for null

Contract.ThrowIfNull(textSnapshot);
if (textSnapshot == null)
{
return;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should (minimally) be a continue, or otherwise we won't connect to the rest of the buffers.

Copy link
Copy Markdown
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

This could mean we don't hook up to other buffers which could be bad.

Changed from return to continue and added a non fatal exception
@chborl
Copy link
Copy Markdown
Contributor Author

chborl commented Feb 13, 2018

@jasonmalinowski , @dpoeschl , @sharwell for review.

namespace Microsoft.CodeAnalysis.Editor.Implementation.InlineRename
{
// Used to aid the investigation of https://github.com/dotnet/roslyn/issues/7364
internal class NullTextBufferException : Exception
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: I'd move this as private class right beside InitializeOpenBuffers so somebody doesn't get the idea of depending on it.

Contract.ThrowIfNull(textSnapshot);
if (textSnapshot == null)
{
FatalError.ReportWithoutCrash(new NullTextBufferException(document));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess we should probably hold onto text as well?

Moved NullTextBufferException to InlineRenameSession and added SourceText.
@heejaechang
Copy link
Copy Markdown
Contributor

we need to re-visit how buffer and snapshot got mapped each other.

@jinujoseph jinujoseph added this to the 15.6 milestone Feb 13, 2018
@jinujoseph
Copy link
Copy Markdown
Contributor

Approved to merge via link

@jinujoseph jinujoseph merged commit 5f551ec into dotnet:dev15.6.x Feb 14, 2018
@chborl chborl deleted the unexpectednull_156 branch October 26, 2018 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants