From 4c997e08741020aa103af5baeec8c1333b3b7b07 Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Tue, 22 Jul 2014 17:19:14 +0400 Subject: [PATCH] Prevent NPE in AbstractPopup and add corresponding logging --- .../com/intellij/ui/popup/AbstractPopup.java | 49 ++++++++++++++----- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java index f25093c6dd8d..78802ccdf6bb 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/AbstractPopup.java @@ -337,7 +337,7 @@ public class AbstractPopup implements JBPopup { } public void setShowHints(boolean show) { - final Window ancestor = SwingUtilities.getWindowAncestor(myComponent); + final Window ancestor = getContentWindow(myComponent); if (ancestor instanceof RootPaneContainer) { final JRootPane rootPane = ((RootPaneContainer)ancestor).getRootPane(); if (rootPane != null) { @@ -828,7 +828,7 @@ public class AbstractPopup implements JBPopup { myPopup.setRequestFocus(myRequestFocus); myPopup.show(); - final Window window = SwingUtilities.getWindowAncestor(myContent); + final Window window = getContentWindow(myContent); myWindow = window; @@ -1208,14 +1208,17 @@ public class AbstractPopup implements JBPopup { size = computeWindowSize(size); - final Window window = SwingUtilities.getWindowAncestor(myContent); - window.setSize(size); + final Window window = getContentWindow(myContent); + if (window != null) { + window.setSize(size); + } } public void pack() { - final Window window = SwingUtilities.getWindowAncestor(myContent); - - window.pack(); + final Window window = getContentWindow(myContent); + if (window != null) { + window.pack(); + } } public JComponent getComponent() { @@ -1234,6 +1237,10 @@ public class AbstractPopup implements JBPopup { } myDisposed = true; + if (LOG.isDebugEnabled()) { + LOG.debug("start disposing " + myContent); + } + Disposer.dispose(this, false); ApplicationManager.getApplication().assertIsDispatchThread(); @@ -1280,6 +1287,10 @@ public class AbstractPopup implements JBPopup { IdeFocusManager.getInstance(myProject).typeAheadUntil(typeAheadDone); getFocusManager().doWhenFocusSettlesDown(runFinal); } + + if (LOG.isDebugEnabled()) { + LOG.debug("stop disposing content"); + } } private void resetWindow() { @@ -1408,15 +1419,27 @@ public class AbstractPopup implements JBPopup { } public static Window moveTo(JComponent content, Point screenPoint, final Dimension headerCorrectionSize) { - setDefaultCursor(content); - final Window wnd = SwingUtilities.getWindowAncestor(content); - if (headerCorrectionSize != null) { - screenPoint.y -= headerCorrectionSize.height; + final Window wnd = getContentWindow(content); + if (wnd != null) { + wnd.setCursor(Cursor.getDefaultCursor()); + if (headerCorrectionSize != null) { + screenPoint.y -= headerCorrectionSize.height; + } + wnd.setLocation(screenPoint); } - wnd.setLocation(screenPoint); return wnd; } + private static Window getContentWindow(Component content) { + Window window = SwingUtilities.getWindowAncestor(content); + if (window == null) { + if (LOG.isDebugEnabled()) { + LOG.debug("no window ancestor for " + content); + } + } + return window; + } + @Override public Point getLocationOnScreen() { Dimension headerCorrectionSize = myLocateByContent ? myHeaderPanel.getPreferredSize() : null; @@ -1490,7 +1513,7 @@ public class AbstractPopup implements JBPopup { } public static void setDefaultCursor(JComponent content) { - final Window wnd = SwingUtilities.getWindowAncestor(content); + final Window wnd = getContentWindow(content); if (wnd != null) { wnd.setCursor(Cursor.getDefaultCursor()); }