From 1fce7e727fed4c6e64c331fb671c4cd1ecf025c9 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 27 Aug 2014 15:04:31 +0200 Subject: [PATCH] avoid NPE if toolwindow doesn't exists (no Debug toolwindow at this moment) It is must not be real situation, such internal errors must be handled in context and some solution suggested to user (edit RC, for example) --- .../execution/runners/ExecutionUtil.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/platform/lang-api/src/com/intellij/execution/runners/ExecutionUtil.java b/platform/lang-api/src/com/intellij/execution/runners/ExecutionUtil.java index 0d15a272498c..b6c300c3f7e2 100644 --- a/platform/lang-api/src/com/intellij/execution/runners/ExecutionUtil.java +++ b/platform/lang-api/src/com/intellij/execution/runners/ExecutionUtil.java @@ -31,6 +31,7 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.MessageType; +import com.intellij.openapi.ui.Messages; import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.ui.content.Content; import com.intellij.util.ObjectUtils; @@ -65,18 +66,19 @@ public class ExecutionUtil { @NotNull final String toolWindowId, @NotNull String taskName, @NotNull ExecutionException e) { - if (e instanceof RunCanceledByUserException) return; + if (e instanceof RunCanceledByUserException) { + return; + } LOG.debug(e); String description = e.getMessage(); - HyperlinkListener listener = null; - if (description == null) { LOG.warn("Execution error without description", e); description = "Unknown error"; } + HyperlinkListener listener = null; if ((description.contains("87") || description.contains("111") || description.contains("206")) && e instanceof ProcessNotCreatedException && !PropertiesComponent.getInstance(project).isTrueValue("dynamic.classpath")) { @@ -110,7 +112,14 @@ public class ExecutionUtil { UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { - ToolWindowManager.getInstance(project).notifyByBalloon(toolWindowId, MessageType.ERROR, fullMessage, null, finalListener); + ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); + if (toolWindowManager.canShowNotification(toolWindowId)) { + //noinspection SSBasedInspection + toolWindowManager.notifyByBalloon(toolWindowId, MessageType.ERROR, fullMessage, null, finalListener); + } + else { + Messages.showErrorDialog(project, fullMessage, ""); + } NotificationListener notificationListener = ObjectUtils.tryCast(finalListener, NotificationListener.class); ourNotificationGroup.createNotification(title, finalDescription, NotificationType.ERROR, notificationListener).notify(project); }