Bug 552160 - NPE with first parent
Summary: NPE with first parent
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.6   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 5.6   Edit
Assignee: Thomas Wolf CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 550210 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-10-17 02:06 EDT by Andrey Loskutov CLA
Modified: 2019-12-03 17:39 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Loskutov CLA 2019-10-17 02:06:03 EDT
Using 5.6.0.201910092056 jgit.

I've had History view opened and "Show first parent only" on, but "Show all branches" off.

Then I've toggled "Show all branches" and got this NPE few seconds later (we have ~8000 branches).

I could not reproduce that.

java.lang.NullPointerException
	at org.eclipse.jgit.revwalk.TopoSortGenerator.<init>(TopoSortGenerator.java:87)
	at org.eclipse.jgit.revwalk.StartGenerator.next(StartGenerator.java:172)
	at org.eclipse.jgit.revwalk.RevWalk.next(RevWalk.java:467)
	at org.eclipse.jgit.revplot.PlotWalk.next(PlotWalk.java:151)
	at org.eclipse.egit.ui.internal.history.SWTWalk.next(SWTWalk.java:58)
	at org.eclipse.egit.ui.internal.history.GitHistoryWalk.next(GitHistoryWalk.java:57)
	at org.eclipse.jgit.revwalk.RevCommitList.fillTo(RevCommitList.java:307)
	at org.eclipse.egit.ui.internal.history.GenerateHistoryJob.run(GenerateHistoryJob.java:105)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Comment 1 Thomas Wolf CLA 2019-10-25 20:02:29 EDT
I think that's a bug in RewriteGenerator.

  for (int i = 0; i < nParents; i++) {
    final RevCommit oldp = pList[i];
    if (firstParent && i > 0) {                      /// (1)
      c.parents = new RevCommit[] { rewrite(oldp) }; /// (2)
      return c;
    }
    final RevCommit newp = rewrite(oldp);
    if (oldp != newp) {
      pList[i] = newp;
      rewrote = true;
    }
  }
  if (rewrote) {
    c.parents = cleanup(pList);
  }

(2) is IMO the problem leading to the NPE: rewrite can return null, and then
there's a commit with a null in its parent array, which causes the NPE in TopoSortGenerator:87.

But I struggle to write a test reproducing this. I had written a test and it failed as expected the first time. But not anymore since then. Huh???

Moreover, I don't understand (1) at all. Why "&& i > 0"?? To me that looks as if in some case first-parent would actually take the second parent.

But for that I haven't succeeded to write a failing test either.

Puzzled...
Comment 2 Eclipse Genie CLA 2019-10-26 10:33:39 EDT
New Gerrit change created: https://git.eclipse.org/r/151657
Comment 3 Eclipse Genie CLA 2019-11-15 19:26:16 EST
Gerrit change https://git.eclipse.org/r/151657 was merged to [master].
Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=1daf6f13aa4a77c32ddc86b829d4e4ec32bb35dd
Comment 4 Thomas Wolf CLA 2019-12-03 17:39:28 EST
*** Bug 550210 has been marked as a duplicate of this bug. ***