瀏覽代碼

Fix NPE when deleting projects from workspace while models are open

Thomas Kutz 7 年之前
父節點
當前提交
37022ce8ef

+ 10 - 2
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editor/StatechartDiagramEditor.java

@@ -10,6 +10,7 @@
  */
 package org.yakindu.sct.ui.editor.editor;
 
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Optional;
 
@@ -177,8 +178,8 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
 				IEditorInput otherInput = e.getEditorInput();
 				IEditorInput thisInput = this.getEditorInput();
 
-				return ID.equals(e.getId()) && !otherInput.equals(thisInput) && ((IFileEditorInput) otherInput)
-						.getFile().getLocationURI().equals(((IFileEditorInput) thisInput).getFile().getLocationURI());
+				return ID.equals(e.getId()) && !otherInput.equals(thisInput)
+						&& equalsLocationURI(otherInput, thisInput);
 			} catch (PartInitException e1) {
 				e1.printStackTrace();
 				return false;
@@ -187,6 +188,13 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
 		return editorWithSameResource;
 	}
 
+	protected boolean equalsLocationURI(IEditorInput otherInput, IEditorInput thisInput) {
+		URI otherLocationURI = ((IFileEditorInput) otherInput).getFile().getLocationURI();
+		URI thisLocationURI = ((IFileEditorInput) thisInput).getFile().getLocationURI();
+		// location URI can be null if project was deleted from workspace
+		return otherLocationURI != null && otherLocationURI.equals(thisLocationURI);
+	}
+
 	protected Injector getEditorInjector() {
 		IDomain domain = DomainRegistry.getDomain(getDiagram().getElement());
 		Injector injector = domain.getInjector(IDomain.FEATURE_EDITOR);