Fix potential NPE
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 15 Nov 2016 14:10:12 +0000 (15:10 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 15 Nov 2016 14:10:12 +0000 (15:10 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java

index fdaa3e0c4c93183bbc737988647e414f6caef12c..24f0c8a8f30484001042e32464e875fd5ef82959 100644 (file)
@@ -103,7 +103,10 @@ public abstract class AbstractUtility {
      * @return a boolean.
      */
     public static boolean closeAll() {
      * @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) {
      * @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;
        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) {
        }
        if(references!=null){
                for (IViewReference reference : references) {