From 48005c5f653367a7ad23ea786dc864b7f9737fa3 Mon Sep 17 00:00:00 2001
From: Patrick Plitzner
Date: Tue, 15 Nov 2016 15:10:12 +0100
Subject: [PATCH] Fix potential NPE
---
.../taxeditor/model/AbstractUtility.java | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java
index fdaa3e0c4..24f0c8a8f 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java
@@ -103,7 +103,10 @@ public abstract class AbstractUtility {
* @return a boolean.
*/
public static boolean closeAll() {
- return getActivePage().closeAllEditors(true);
+ if(getActivePage()!=null){
+ return getActivePage().closeAllEditors(true);
+ }
+ return false;
}
/**
@@ -217,14 +220,14 @@ public abstract class AbstractUtility {
* @return a {@link org.eclipse.ui.IViewPart} object.
*/
public static IViewPart getView(String id, boolean restore) {
- IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
IViewReference[] references = null;
- if(activeWorkbenchWindow!=null){
- references = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage().getViewReferences();
+ if(activeWorkbenchWindow!=null && activeWorkbenchWindow.getActivePage()!=null){
+ references = activeWorkbenchWindow.getActivePage().getViewReferences();
}
- else if(PlatformUI.getWorkbench().getWorkbenchWindows().length>0){
- references = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage().getViewReferences();
+ else if(workbench.getWorkbenchWindows().length>0 && workbench.getWorkbenchWindows()[0].getActivePage()!=null){
+ references = workbench.getWorkbenchWindows()[0].getActivePage().getViewReferences();
}
if(references!=null){
for (IViewReference reference : references) {
--
2.34.1