Skip to content

Fix NullReferenceException #827

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

Merged
merged 2 commits into from
Apr 8, 2016
Merged

Conversation

SzymonPobiega
Copy link
Contributor

Fixes

1>MSBUILD : warning : WARN [04/07/16 20:54:31:12] Could not determine assembly version: System.NullReferenceException: Object reference not set to an instance of an object.
1>MSBUILD : warning :    at GitVersion.LibGitExtensions.<>c.<FindCommitBranchWasBranchedFrom>b__3_6(<>f__AnonymousType2`2 b)
1>MSBUILD : warning :    at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count)
1>MSBUILD : warning :    at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
1>MSBUILD : warning :    at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__1.MoveNext()
1>MSBUILD : warning :    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
1>MSBUILD : warning :    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
1>MSBUILD : warning :    at GitVersion.LibGitExtensions.FindCommitBranchWasBranchedFrom(Branch branch, IRepository repository, Branch[] excludedBranches)
1>MSBUILD : warning :    at GitVersion.VersionCalculation.BaseVersionCalculators.VersionInBranchBaseVersionStrategy.<GetVersions>d__0.MoveNext()
1>MSBUILD : warning :    at System.Linq.Enumerable.<SelectManyIterator>d__16`2.MoveNext()
1>MSBUILD : warning :    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
1>MSBUILD : warning :    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
1>MSBUILD : warning :    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
1>MSBUILD : warning :    at GitVersion.VersionCalculation.BaseVersionCalculator.GetBaseVersion(GitVersionContext context)
1>MSBUILD : warning :    at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion(GitVersionContext context)
1>MSBUILD : warning :    at GitVersion.GitVersionFinder.FindVersion(GitVersionContext context)
1>MSBUILD : warning :    at GitVersion.ExecuteCore.ExecuteInternal(String targetBranch, String commitId, IRepository repo, GitPreparer gitPreparer, String projectRoot, IBuildServer buildServer)
1>MSBUILD : warning :    at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId)
1>MSBUILD : warning :    at GitVersion.ExecuteCore.TryGetVersion(String directory, VersionVariables& versionVariables, Boolean noFetch, Authentication authentication)

I guess that the b => b != null check was OK but then the result type of the Select was changed from Commit to an anonymous type and the check stopped to prevent null commits to come to downstream operators.

@@ -113,7 +113,7 @@ public static Commit FindCommitBranchWasBranchedFrom([NotNull] this Branch branc
mergeBaseCommit = findMergeBase,
branch = otherBranch
};
}).Where(b => b != null).OrderByDescending(b => b.mergeBaseCommit.Committer.When).ToList();
}).Where(b => b.mergeBaseCommit != null).OrderByDescending(b => b.mergeBaseCommit.Committer.When).ToList();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can b be null as the original code suggests? Then it would need to be

Where(b => b != null && b.mergeBaseCommit != null)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍, updated

Copy link
Contributor

Choose a reason for hiding this comment

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

Scratch my comment. I read the entire file and it cannot be null since the select returns a new anonymous object

@pascalberger
Copy link
Member

Thanks! LGTM. As @danielmarbach mentioned the null check on b is not required. If you can revert back to your first version I can merge this.

@SzymonPobiega
Copy link
Contributor Author

@pascalberger what about like 76?

@pascalberger
Copy link
Member

@SzymonPobiega Good catch 👍 Missed this one.

@pascalberger pascalberger merged commit 1134ade into GitTools:master Apr 8, 2016
@danielmarbach
Copy link
Contributor

Could we get a 3.4.2 patch?

Am 08.04.2016 um 09:12 schrieb Pascal Berger [email protected]:

@SzymonPobiega Good catch Missed this one.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub

@pascalberger
Copy link
Member

Needs to be done by @JakeGinnivan. What do you think? Maybe just a patch release with this commit and without any of the other changes if they are not properly tested yet.

@danielmarbach
Copy link
Contributor

Patch would be awesome

Am 08.04.2016 um 09:17 schrieb Pascal Berger [email protected]:

Needs to be done by @JakeGinnivan. What do you think? Maybe just a patch release with this commit and without any of the other changes if they are not properly tested yet.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub

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.

3 participants