Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2016-05-19 09:39:31 +0000
committerMatthias Sohn2016-05-19 22:12:06 +0000
commit63a8fdc2e94e8c1514b04e096f445b296516ddeb (patch)
tree477e90a2ec74f449cac2f4af8e6cc69e2d8db444
parent43a6e3c8ddf423904c5bf3a3f58792c0eec15195 (diff)
downloadegit-63a8fdc2e94e8c1514b04e096f445b296516ddeb.tar.gz
egit-63a8fdc2e94e8c1514b04e096f445b296516ddeb.tar.xz
egit-63a8fdc2e94e8c1514b04e096f445b296516ddeb.zip
Check HandlerUtil.getActiveSite(event) result to avoid NPE's
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/GarbageCollectCommand.java13
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/RemoveCommand.java16
2 files changed, 21 insertions, 8 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/GarbageCollectCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/GarbageCollectCommand.java
index d5dae759c5..2345710a14 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/GarbageCollectCommand.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/GarbageCollectCommand.java
@@ -25,9 +25,9 @@ import org.eclipse.egit.ui.internal.CommonUtils;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryNode;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
+import org.eclipse.ui.services.IServiceLocator;
/**
* Command to run jgit garbage collector
@@ -80,9 +80,14 @@ public class GarbageCollectCommand extends
return Status.OK_STATUS;
}
};
- IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
- IWorkbenchSiteProgressService service = CommonUtils.getService(activeSite, IWorkbenchSiteProgressService.class);
- service.schedule(job);
+ IServiceLocator serviceLocator = HandlerUtil.getActiveSite(event);
+ if (serviceLocator != null) {
+ IWorkbenchSiteProgressService service = CommonUtils.getService(
+ serviceLocator, IWorkbenchSiteProgressService.class);
+ service.schedule(job);
+ } else {
+ job.schedule();
+ }
return null;
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/RemoveCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/RemoveCommand.java
index e5a62b6b3a..900ad40e91 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/RemoveCommand.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/RemoveCommand.java
@@ -56,10 +56,10 @@ import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
import org.eclipse.jgit.util.FileUtils;
import org.eclipse.osgi.util.NLS;
-import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
+import org.eclipse.ui.services.IServiceLocator;
/**
* "Removes" one or several nodes
@@ -81,8 +81,12 @@ public class RemoveCommand extends
*/
protected void removeRepository(final ExecutionEvent event,
final boolean delete) {
- IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
- IWorkbenchSiteProgressService service = CommonUtils.getService(activeSite, IWorkbenchSiteProgressService.class);
+ IServiceLocator serviceLocator = HandlerUtil.getActiveSite(event);
+ IWorkbenchSiteProgressService service = null;
+ if (serviceLocator != null) {
+ service = CommonUtils.getService(serviceLocator,
+ IWorkbenchSiteProgressService.class);
+ }
// get selected nodes
final List<RepositoryNode> selectedNodes;
@@ -192,7 +196,11 @@ public class RemoveCommand extends
}
};
- service.schedule(job);
+ if (service == null) {
+ job.schedule();
+ } else {
+ service.schedule(job);
+ }
}
private void deleteProjects(

Back to the top