Bug 569962 - NPE in DirCacheCheckout on checkout --force if file not in index
Summary: NPE in DirCacheCheckout on checkout --force if file not in index
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.10   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 5.11   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-30 04:07 EST by Thomas Wolf CLA
Modified: 2020-12-31 12:03 EST (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 Thomas Wolf CLA 2020-12-30 04:07:49 EST
The NPE occurs on a checkout --force if there is a file that exists in head, merge, and working tree, but not in the index.

Reproducer:

$ mkdir chktest
$ cd chktest
$ git init
$ echo foo > foo.txt
$ git add foo.txt
$ git commit -m "initial"
[master (root-commit) 531b309] initial
 1 file changed, 1 insertion(+)
 create mode 100644 foo.txt
$ git checkout -b test
Switched to a new branch 'test'
$ echo bar > bar.txt
$ git add bar.txt
$ git commit -m "bar.txt"
[test 748158a] bar.txt
 1 file changed, 1 insertion(+)
 create mode 100644 bar.txt
$ git checkout master
Switched to branch 'master'
$ echo bar > bar.txt
$ git add bar.txt
$ git commit -m "bar on master"
[master d381c79] bar on master
 1 file changed, 1 insertion(+)
 create mode 100644 bar.txt
$ git rm --cached bar.txt
rm 'bar.txt'
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	deleted:    bar.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	bar.txt

$ git checkout --force test
Switched to branch 'test'
$ git status
On branch test
nothing to commit, working tree clean
$ git checkout master
Switched to branch 'master'
$ git rm --cached bar.txt
rm 'bar.txt'
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	deleted:    bar.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	bar.txt

$ ../jgit-5.10.sh checkout --force test
java.lang.NullPointerException
	at org.eclipse.jgit.dircache.DirCacheCheckout.checkoutEntry(DirCacheCheckout.java:1452)
	at org.eclipse.jgit.dircache.DirCacheCheckout.keep(DirCacheCheckout.java:1222)
	at org.eclipse.jgit.dircache.DirCacheCheckout.processEntry(DirCacheCheckout.java:952)
	at org.eclipse.jgit.dircache.DirCacheCheckout.preScanTwoTrees(DirCacheCheckout.java:309)
	at org.eclipse.jgit.dircache.DirCacheCheckout.doCheckout(DirCacheCheckout.java:496)
	at org.eclipse.jgit.dircache.DirCacheCheckout.checkout(DirCacheCheckout.java:467)
	at org.eclipse.jgit.api.CheckoutCommand.call(CheckoutCommand.java:248)
	at org.eclipse.jgit.pgm.Checkout.run(Checkout.java:82)
	at org.eclipse.jgit.pgm.TextBuiltin.execute(TextBuiltin.java:235)
	at org.eclipse.jgit.pgm.Main.execute(Main.java:245)
	at org.eclipse.jgit.pgm.Main.run(Main.java:133)
	at org.eclipse.jgit.pgm.Main.main(Main.java:105)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Comment 1 Eclipse Genie CLA 2020-12-30 04:20:46 EST
New Gerrit change created: https://git.eclipse.org/r/c/jgit/jgit/+/174143