From 448c661991446195d7fef50c2761de19df5fc640 Mon Sep 17 00:00:00 2001 From: Zoltan Ujhelyi Date: Wed, 6 Feb 2019 10:06:57 +0100 Subject: [PATCH] Hopeful fix for an NPE when project load is cancelled #23 --- .../src/main/com/incquerylabs/v4md/ViatraQueryAdapter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/ViatraQueryAdapter.java b/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/ViatraQueryAdapter.java index e133432..729f59b 100644 --- a/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/ViatraQueryAdapter.java +++ b/com.incquerylabs.v4md/src/main/com/incquerylabs/v4md/ViatraQueryAdapter.java @@ -45,8 +45,8 @@ public void wipeEngine(){ public static Optional getAdapter(Project project) { Objects.requireNonNull(project, "ViatraQueryAdapter cannot be provided for a null Project"); - return project.getPrimaryModel().eAdapters().stream().filter(ViatraQueryAdapter.class::isInstance) - .map(ViatraQueryAdapter.class::cast).findAny(); + return Optional.ofNullable(project.getPrimaryModel()).flatMap(m -> m.eAdapters().stream() + .filter(ViatraQueryAdapter.class::isInstance).map(ViatraQueryAdapter.class::cast).findAny()); } public static ViatraQueryAdapter getOrCreateAdapter(Project project, Notifier... notifiers) {