Bug 462671 - RecursiveMerger fails with NPE when no merge base exists
Summary: RecursiveMerger fails with NPE when no merge base exists
Status: ASSIGNED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 3.6   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Christian Halstrick CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-20 07:57 EDT by Sasa Zivkov CLA
Modified: 2015-03-25 06:02 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sasa Zivkov CLA 2015-03-20 07:57:55 EDT
The RecursiveMerger will throw a NPE when there is no merge base for the commits it is trying to merge. Example stack trace [1].


[1]
Caused by: java.lang.NullPointerException: while trying to invoke the method org.eclipse.jgit.revwalk.RevCommit.getTree() of a null object returned from org.eclipse.jgit.merge.RecursiveMerger.getBaseCommit(org.eclipse.jgit.revwalk.RevCommit, org.eclipse.jgit.revwalk.RevCommit, int)
        at org.eclipse.jgit.merge.RecursiveMerger.getBaseCommit(RecursiveMerger.java:197)
        at org.eclipse.jgit.merge.RecursiveMerger.getBaseCommit(RecursiveMerger.java:125)
        at org.eclipse.jgit.merge.ThreeWayMerger.mergeBase(ThreeWayMerger.java:132)
        at org.eclipse.jgit.merge.ResolveMerger.mergeImpl(ResolveMerger.java:301)
        at org.eclipse.jgit.merge.Merger.merge(Merger.java:203)
        at org.eclipse.jgit.merge.Merger.merge(Merger.java:156)
        at org.eclipse.jgit.merge.ThreeWayMerger.merge(ThreeWayMerger.java:114)
Comment 1 Christian Halstrick CLA 2015-03-20 08:10:22 EDT
I debugged and found out that this is a bug when JGit should merge two tips which have no common ancestor (the repo has at least two roots r1,r2 and one tip is ancestor of r1 and the other of r2). Not all such cases are buggy ... but some of them are. And we have no test for that. Definitly a severe bug.

I'll continue fixing and writing tests which cover this. At least the situation is reproducable.
Comment 2 Christian Halstrick CLA 2015-03-25 06:02:35 EDT
The bug was not as bad as thought in the beginning. To hit this bug it was not necessary that the commits you want to merge don't have a common predecessor. Instead it was required that you

- want to merge m1, m2
- m1 and m2 have multiple common base commits b1, b2 (means: there was a criss-cross merge)
- the found base commits b1, b2 don't have a common predecessor (they are derived from different root commits)

Example:

m1--m2
  \/
  /\
s1--s2

In this case m1 and s2 do have common base commits (m1 & s1) but these base commits have no common base.

Proposed a fix here: https://git.eclipse.org/r/#/c/44567