Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit d240141

Browse files
committed
Handle potential NullReferenceExceptions
1 parent cb03ede commit d240141

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/GitHub.Exports/Services/VSServices.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Microsoft.TeamFoundation.Git.Controls.Extensibility;
22
using System;
33
using System.ComponentModel.Composition;
4-
using System.Diagnostics;
54
using System.Globalization;
65
using System.Linq;
76
using GitHub.Extensions;
@@ -116,7 +115,7 @@ static IEnumerable<ISimpleRepositoryModel> PokeTheRegistryForRepositoryList()
116115
{
117116
using (var subkey = key.OpenSubKey(x))
118117
{
119-
var path = subkey.GetValue("Path") as string;
118+
var path = subkey?.GetValue("Path") as string;
120119
if (path != null)
121120
{
122121
var uri = VisualStudio.Services.GetRepoFromPath(path)?.GetUri();
@@ -136,8 +135,7 @@ static string PokeTheRegistryForLocalClonePath()
136135
{
137136
using (var key = OpenGitKey("General"))
138137
{
139-
if (key == null) return null;
140-
return (string)key.GetValue("DefaultRepositoryPath", string.Empty, RegistryValueOptions.DoNotExpandEnvironmentNames);
138+
return (string)key?.GetValue("DefaultRepositoryPath", string.Empty, RegistryValueOptions.DoNotExpandEnvironmentNames);
141139
}
142140
}
143141

@@ -147,8 +145,8 @@ public string SetDefaultProjectPath(string path)
147145
string old;
148146
using (var key = Registry.CurrentUser.OpenSubKey(PathsKey, true))
149147
{
150-
old = (string)key.GetValue("Value0", string.Empty, RegistryValueOptions.DoNotExpandEnvironmentNames);
151-
key.SetValue("Value0", path, RegistryValueKind.String);
148+
old = (string)key?.GetValue("Value0", string.Empty, RegistryValueOptions.DoNotExpandEnvironmentNames);
149+
key?.SetValue("Value0", path, RegistryValueKind.String);
152150
}
153151
return old;
154152
}

src/GitHub.VisualStudio/UI/Views/GitHubConnectContent.xaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
7676

7777
var item = values[0] as ISimpleRepositoryModel;
7878
var context = values[1] as IGitHubConnectSection;
79+
if (item == null)
80+
return String.Empty;
7981
if (context == null)
80-
return item?.Name ?? String.Empty;
82+
return item.Name ?? String.Empty;
8183

8284
if (context.SectionConnection.Username == item.CloneUrl.Owner)
8385
return item.CloneUrl.RepositoryName;

0 commit comments

Comments
 (0)