Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 361096

Summary: NPE in WorkspaceRoot.findContainersForLocationURI
Product: [Technology] EGit Reporter: Dani Megert <daniel_megert>
Component: CoreAssignee: Project Inbox <egit.core-inbox>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jurgen.vinju, markus.kell.r, matthias.sohn, pwebster, remy.suen, robin.rosenberg, robin
Version: 1.2   
Target Milestone: 2.3   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Dani Megert CLA 2011-10-17 03:39:32 EDT
Found this in .log:

!ENTRY org.eclipse.core.jobs 4 2 2011-10-14 09:27:42.073
!MESSAGE An internal error occurred during: "Re-indexing repository eclipse.platform.ui".
!STACK 0
java.lang.NullPointerException
	at org.eclipse.core.internal.resources.WorkspaceRoot.findContainersForLocationURI(WorkspaceRoot.java:89)
	at org.eclipse.core.internal.resources.WorkspaceRoot.findContainersForLocationURI(WorkspaceRoot.java:80)
	at org.eclipse.egit.core.IteratorService.findContainer(IteratorService.java:59)
	at org.eclipse.egit.core.AdaptableFileTreeIterator.createSubtreeIterator(AdaptableFileTreeIterator.java:83)
	at org.eclipse.jgit.treewalk.AbstractTreeIterator.createSubtreeIterator(AbstractTreeIterator.java:527)
	at org.eclipse.jgit.treewalk.TreeWalk.enterSubtree(TreeWalk.java:907)
	at org.eclipse.jgit.treewalk.TreeWalk.next(TreeWalk.java:566)
	at org.eclipse.jgit.lib.IndexDiff.diff(IndexDiff.java:284)
	at org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry.calcIndexDiff(IndexDiffCacheEntry.java:265)
	at org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry.access$2(IndexDiffCacheEntry.java:256)
	at org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry$3.run(IndexDiffCacheEntry.java:151)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Comment 1 Jurgen Vinju CLA 2012-08-03 07:37:29 EDT
I have this "all the time". I do have linkedResources in these projects, which may be relevant. I don't know. The other special thing may be that I only have these exceptions in the second level Eclipse that I run. 

Is there a known workaround?
Comment 2 Jurgen Vinju CLA 2012-08-07 03:49:32 EDT
We have further isolated the issue. It is caused by the existence of a linkedResource in a .project file. Without it, the bug does not occur, with the linkedResource the problem hits every time we safe _any_ file in _any_ project. 

Thanks!
Comment 3 Markus Keller CLA 2012-11-26 09:15:59 EST
Got this during shutdown with EGit 2.1.0.201209190230-r. Looks like the INDEX_DIFF_CACHE_UPDATE job should be cancelled on shutdown.
Comment 4 Robin Stocker CLA 2013-01-14 12:29:14 EST
Could this be a duplicate of bug 396900?

For supporting linked resources, please see bug 333338.
Comment 5 Dani Megert CLA 2013-01-15 06:48:57 EST
(In reply to comment #4)
> Could this be a duplicate of bug 396900?

Yes.
Comment 6 Robin Stocker CLA 2013-01-18 07:38:46 EST
Ok, closed as duplicate.

*** This bug has been marked as a duplicate of bug 396900 ***
Comment 7 Dani Megert CLA 2013-01-25 06:54:06 EST
The fix for bug did not fix this. With 2.3.0.201301242209 I still get NPEs on exit:

- ContainerTreeIterator$ResourceEntry.asFile(ContainerTreeIterator.java:346)
- WorkspaceRoot.findContainersForLocationURI(WorkspaceRoot.java:89)


ENTRY org.eclipse.core.jobs 4 2 2013-01-25 12:48:39.214
!MESSAGE An internal error occurred during: "Re-indexing repository eclipse.jdt.debug".
!STACK 0
java.lang.NullPointerException
	at org.eclipse.egit.core.ContainerTreeIterator$ResourceEntry.asFile(ContainerTreeIterator.java:346)
	at org.eclipse.egit.core.ContainerTreeIterator$ResourceEntry.getLength(ContainerTreeIterator.java:312)
	at org.eclipse.jgit.treewalk.WorkingTreeIterator.getEntryLength(WorkingTreeIterator.java:491)
	at org.eclipse.jgit.treewalk.WorkingTreeIterator.compareMetadata(WorkingTreeIterator.java:749)
	at org.eclipse.jgit.treewalk.WorkingTreeIterator.isModified(WorkingTreeIterator.java:791)
	at org.eclipse.jgit.treewalk.filter.IndexDiffFilter.include(IndexDiffFilter.java:221)
	at org.eclipse.jgit.treewalk.filter.AndTreeFilter$List.include(AndTreeFilter.java:163)
	at org.eclipse.jgit.treewalk.TreeWalk.next(TreeWalk.java:560)
	at org.eclipse.jgit.lib.IndexDiff.diff(IndexDiff.java:287)
	at org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry.calcIndexDiffDataFull(IndexDiffCacheEntry.java:452)
	at org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry.access$5(IndexDiffCacheEntry.java:441)
	at org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry$4.run(IndexDiffCacheEntry.java:263)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

!ENTRY org.eclipse.core.jobs 4 2 2013-01-25 12:48:39.382
!MESSAGE An internal error occurred during: "Re-indexing repository eclipse.platform.team".
!STACK 0
java.lang.NullPointerException
	at org.eclipse.core.internal.resources.WorkspaceRoot.findContainersForLocationURI(WorkspaceRoot.java:89)
	at org.eclipse.core.internal.resources.WorkspaceRoot.findContainersForLocationURI(WorkspaceRoot.java:80)
	at org.eclipse.egit.core.IteratorService.findContainer(IteratorService.java:66)
	at org.eclipse.egit.core.AdaptableFileTreeIterator.createSubtreeIterator(AdaptableFileTreeIterator.java:82)
	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.calcIndexDiffDataFull(IndexDiffCacheEntry.java:452)
	at org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry.access$5(IndexDiffCacheEntry.java:441)
	at org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry$4.run(IndexDiffCacheEntry.java:263)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Comment 8 Robin Stocker CLA 2013-01-25 16:16:22 EST
(In reply to comment #7)
> The fix for bug did not fix this. With 2.3.0.201301242209 I still get NPEs
> on exit:
> 
> - ContainerTreeIterator$ResourceEntry.asFile(ContainerTreeIterator.java:346)

Fix for that:

https://git.eclipse.org/r/9937

> - WorkspaceRoot.findContainersForLocationURI(WorkspaceRoot.java:89)

I don't know how this should be prevented, apart from trying to see if ResourcesPlugin.getWorkspace() throws an ISE before attempting to call findContainersForLocationURI.

Or should we join the INDEX_DIFF_CACHE_UPDATE job in IndexDiffCache's dispose?
Comment 9 Robin Rosenberg CLA 2013-01-27 18:40:05 EST
(In reply to comment #8)
> (In reply to comment #7)
> > The fix for bug did not fix this. With 2.3.0.201301242209 I still get NPEs
> > on exit:
> > 
> > - ContainerTreeIterator$ResourceEntry.asFile(ContainerTreeIterator.java:346)
> 
> Fix for that:
> 
> https://git.eclipse.org/r/9937
> 
> > - WorkspaceRoot.findContainersForLocationURI(WorkspaceRoot.java:89)
> 
> I don't know how this should be prevented, apart from trying to see if
> ResourcesPlugin.getWorkspace() throws an ISE before attempting to call
> findContainersForLocationURI.
> 
> Or should we join the INDEX_DIFF_CACHE_UPDATE job in IndexDiffCache's
> dispose?

I think this is the one.
Comment 10 Matthias Sohn CLA 2013-01-31 18:15:05 EST
merged https://git.eclipse.org/r/#/c/9937/ as 10cdd651b8acef99b4a89a2fc5732d1043d47b5b
Comment 11 Dani Megert CLA 2013-02-01 02:26:14 EST
> Or should we join the INDEX_DIFF_CACHE_UPDATE job in IndexDiffCache's dispose?

The jobs must be cancelled (or waited upon) when the EGit bundle gets stopped. Catching the exception would prevent the NPE, but we would still get the following warning when the core plug-in shuts down:

!ENTRY org.eclipse.core.jobs 2 2 2013-02-01 08:19:00.810
!MESSAGE Job found still running after platform shutdown.  Jobs should be canceled by the plugin that scheduled them during shutdown: org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry$4
Comment 12 Robin Stocker CLA 2013-02-01 06:49:11 EST
(In reply to comment #11)
> > Or should we join the INDEX_DIFF_CACHE_UPDATE job in IndexDiffCache's dispose?
> 
> The jobs must be cancelled (or waited upon) when the EGit bundle gets
> stopped.

We did cancel it already, with the following it should now also be done before continuing:

https://git.eclipse.org/r/10097
Comment 13 Matthias Sohn CLA 2013-02-02 18:58:42 EST
merged as 116f474cb7cfbd03536e82768a552711f17ff3d8
Comment 14 Dani Megert CLA 2013-02-04 11:33:13 EST
Verified that this fixes the problem.
Comment 15 Dani Megert CLA 2013-03-20 04:08:08 EDT
*** Bug 381858 has been marked as a duplicate of this bug. ***