Skip to content

Commit

Permalink
[release/5.0] Fix NRE introduced in FileSystemWatcher during nullabil…
Browse files Browse the repository at this point in the history
…ity annotations (#41339)

* Fix NRE introduced during nullability annotations

* Apply Jeff's suggestions from code review

Co-authored-by: Jeff Handley <jeffhandley@users.noreply.github.com>

Co-authored-by: Krzysztof Wicher <kwicher@microsoft.com>
Co-authored-by: Krzysztof Wicher <mordotymoja@gmail.com>
Co-authored-by: Jeff Handley <jeffhandley@users.noreply.github.com>
  • Loading branch information
4 people authored Aug 25, 2020
1 parent 3120d4a commit 2aa627b
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,12 @@ private void AddDirectoryWatchUnlocked(WatchedDirectory? parent, string director
// of the world, but there's little that can be done about that.)
if (directoryEntry.Parent != parent)
{
directoryEntry.Parent?.Children!.Remove (directoryEntry);
// Work around https://github.com/dotnet/csharplang/issues/3393 preventing Parent?.Children!. from behaving as expected
if (directoryEntry.Parent != null)
{
directoryEntry.Parent.Children!.Remove(directoryEntry);
}

directoryEntry.Parent = parent;
if (parent != null)
{
Expand Down Expand Up @@ -443,7 +448,12 @@ private void RemoveWatchedDirectory(WatchedDirectory directoryEntry, bool remove
Debug.Assert (_includeSubdirectories);
lock (SyncObj)
{
directoryEntry.Parent?.Children!.Remove(directoryEntry);
// Work around https://github.com/dotnet/csharplang/issues/3393 preventing Parent?.Children!. from behaving as expected
if (directoryEntry.Parent != null)
{
directoryEntry.Parent.Children!.Remove(directoryEntry);
}

RemoveWatchedDirectoryUnlocked (directoryEntry, removeInotify);
}
}
Expand Down

0 comments on commit 2aa627b

Please sign in to comment.