From d26772c93995564d8e6ae88e0d18a28df27392a7 Mon Sep 17 00:00:00 2001 From: Axel RICHARD Date: Thu, 7 Jan 2021 10:16:07 +0100 Subject: [PATCH] Fix potential NPE Change-Id: Ica3669bad719f5d553567ac0072ef2393d213391 Signed-off-by: Axel RICHARD --- .../actions/SelectDiffAction.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/SelectDiffAction.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/SelectDiffAction.java index 61d039553..cc2b52325 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/SelectDiffAction.java +++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/SelectDiffAction.java @@ -17,6 +17,10 @@ import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin; import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.Navigatable; import org.eclipse.jface.action.Action; import org.eclipse.jface.commands.ActionHandler; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.handlers.IHandlerActivation; import org.eclipse.ui.handlers.IHandlerService; @@ -113,9 +117,21 @@ public class SelectDiffAction extends Action { @SuppressWarnings("cast") protected IHandlerService getHandlerService() { - // explicit cast necessary for Luna - return (IHandlerService)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() - .getActivePart().getSite().getService(IHandlerService.class); + if (PlatformUI.isWorkbenchRunning()) { + IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); + if (activePage != null) { + IWorkbenchPart activePart = activePage.getActivePart(); + if (activePart != null) { + IWorkbenchPartSite site = activePart.getSite(); + if (site != null) { + // explicit cast necessary for Luna + return (IHandlerService)site.getService(IHandlerService.class); + } + } + } + } + return null; } /** -- 2.11.4.GIT