eclipse/egit — pull request #2 by jwadamson (2013-03-22 12:34:28+00:00)
Title: Fix NullPointerException while computing IndexDiff of updating Index

Recently I've been getting multiple NPE when I change branches of a repo which is in egit from the command line.

> !ENTRY org.eclipse.core.jobs 4 2 2013-03-21 16:04:59.290
> !MESSAGE An internal error occurred during: "Re-indexing repository core".
> !STACK 0
> java.lang.NullPointerException
>	at org.eclipse.egit.core.ContainerTreeIterator.addFilteredEntries(ContainerTreeIterator.java:241)
>	at org.eclipse.egit.core.ContainerTreeIterator.entries(ContainerTreeIterator.java:178)
>	at org.eclipse.egit.core.ContainerTreeIterator.(ContainerTreeIterator.java:135)
>	at org.eclipse.egit.core.ContainerTreeIterator.createSubtreeIterator(ContainerTreeIterator.java:144)
>	at org.eclipse.jgit.treewalk.AbstractTreeIterator.createSubtreeIterator(AbstractTreeIterator.java:528)
>	at org.eclipse.jgit.treewalk.TreeWalk.enterSubtree(TreeWalk.java:908)
>	at org.eclipse.jgit.treewalk.TreeWalk.next(TreeWalk.java:566)
>	at org.eclipse.jgit.lib.IndexDiff.diff(IndexDiff.java:287)
>	at org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry.calcIndexDiffDataIncremental(IndexDiffCacheEntry.java:404)
>	at org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry.access$9(IndexDiffCacheEntry.java:384)
>	at org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry$5.run(IndexDiffCacheEntry.java:344)
>	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

Judging by the code it would appear that the treewalk is trying to go over directories or files that have just been removed, so the File instance for the containerLocation that is returned is no longer a directory on disk. This makes the listFiles method return null, which then raises a NPE when the Iterator attempts to iterate on the array,