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

Commit 6f41c5b

Browse files
committed
Handle null return values from registry methods.
`RegistryKey.OpenSubKey` can return null, check for null values before trying to do anything. Fixes #978
1 parent ba29d80 commit 6f41c5b

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

src/GitHub.TeamFoundation.14/RegistryHelper.cs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,42 @@ static RegistryKey OpenGitKey(string path)
2121

2222
internal static IEnumerable<ILocalRepositoryModel> PokeTheRegistryForRepositoryList()
2323
{
24-
using (var key = OpenGitKey("Repositories"))
24+
var key = OpenGitKey("Repositories");
25+
26+
if (key != null)
2527
{
26-
return key.GetSubKeyNames().Select(x =>
28+
using (key)
2729
{
28-
using (var subkey = key.OpenSubKey(x))
30+
return key.GetSubKeyNames().Select(x =>
2931
{
30-
try
31-
{
32-
var path = subkey?.GetValue("Path") as string;
33-
if (path != null && Directory.Exists(path))
34-
return new LocalRepositoryModel(path);
35-
}
36-
catch (Exception)
32+
var subkey = key.OpenSubKey(x);
33+
34+
if (subkey != null)
3735
{
38-
// no sense spamming the log, the registry might have ton of stale things we don't care about
36+
using (subkey)
37+
{
38+
try
39+
{
40+
var path = subkey?.GetValue("Path") as string;
41+
if (path != null && Directory.Exists(path))
42+
return new LocalRepositoryModel(path);
43+
}
44+
catch (Exception)
45+
{
46+
// no sense spamming the log, the registry might have ton of stale things we don't care about
47+
}
48+
49+
}
3950
}
51+
4052
return null;
41-
}
42-
})
43-
.Where(x => x != null)
44-
.ToList();
53+
})
54+
.Where(x => x != null)
55+
.ToList();
56+
}
4557
}
58+
59+
return new ILocalRepositoryModel[0];
4660
}
4761

4862
internal static string PokeTheRegistryForLocalClonePath()

0 commit comments

Comments
 (0)