Subject: [PATCH] Fix nullpointer exceptions in Quickdiff

From: Robin Rosenberg <[email-masked]>
Date: Fri, 11 Jul 2008 23:34:47 +0200

--- 
I saw some problem when resources were no longer in the worspace, such as during a bisectg. 
This one should probably just be squashed into patch 1.

-- robin

diff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitDocument.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitDocument.java
index ebed0cf..3724304 100644
--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitDocument.java
+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitDocument.java
@@ -43,7 +43,10 @@ class GitDocument extends Document implements RepositoryListener {
 	void populate() throws IOException {
 		set("");
 		final IProject project = resource.getProject();
-		final String gitPath = RepositoryMapping.getMapping(project).getRepoRelativePath(resource);
+		RepositoryMapping mapping = RepositoryMapping.getMapping(project);
+		if (mapping == null)
+			return;
+		final String gitPath = mapping.getRepoRelativePath(resource);
 		final Repository repository = getRepository();
 		repository.addRepositoryChangedListener(this);
 		String baseline = GitQuickDiffProvider.baseline.get(repository);
@@ -63,7 +66,9 @@ class GitDocument extends Document implements RepositoryListener {
 	}
 
 	void dispose() {
-		getRepository().removeRepositoryChangedListener(this);
+		Repository repository = getRepository();
+		if (repository != null)
+			repository.removeRepositoryChangedListener(this);
 	}
 
 	public void refsChanged(final RefsChangedEvent e) {
@@ -81,6 +86,8 @@ class GitDocument extends Document implements RepositoryListener {
 	private Repository getRepository() {
 		IProject project = resource.getProject();
 		RepositoryMapping mapping = RepositoryMapping.getMapping(project);
-		return mapping.getRepository();
+		if (mapping != null)
+			return mapping.getRepository();
+		return null;
 	}
 }
-- 
1.5.6.2.220.g44701