6740974: api/javax_swing/PopupFactory/index.html#Ctor[PopupFactory2002] fails with NPE
authorpeterz
Tue, 07 Apr 2009 12:40:58 +0400
changeset 2496 c0dfcd9b27f7
parent 2495 3e32bdf43a35
child 2497 903fd9d785ef
6740974: api/javax_swing/PopupFactory/index.html#Ctor[PopupFactory2002] fails with NPE Reviewed-by: malenkov
jdk/src/share/classes/javax/swing/PopupFactory.java
--- a/jdk/src/share/classes/javax/swing/PopupFactory.java	Mon Apr 06 13:06:24 2009 +0400
+++ b/jdk/src/share/classes/javax/swing/PopupFactory.java	Tue Apr 07 12:40:58 2009 +0400
@@ -552,14 +552,15 @@
             boolean result = false;
             Component component = getComponent();
             if (owner != null && component != null) {
-                Container parent = (Container) SwingUtilities.getRoot(owner);
                 int popupWidth = component.getWidth();
                 int popupHeight = component.getHeight();
-                Rectangle parentBounds = parent.getBounds();
+
+                Container parent = (Container) SwingUtilities.getRoot(owner);
                 if (parent instanceof JFrame ||
                     parent instanceof JDialog ||
                     parent instanceof JWindow) {
 
+                    Rectangle parentBounds = parent.getBounds();
                     Insets i = parent.getInsets();
                     parentBounds.x += i.left;
                     parentBounds.y += i.top;
@@ -577,11 +578,11 @@
                                 .contains(x, y, popupWidth, popupHeight);
                     }
                 } else if (parent instanceof JApplet) {
+                    Rectangle parentBounds = parent.getBounds();
                     Point p = parent.getLocationOnScreen();
                     parentBounds.x = p.x;
                     parentBounds.y = p.y;
-                    result = parentBounds
-                            .contains(x, y, popupWidth, popupHeight);
+                    result = parentBounds.contains(x, y, popupWidth, popupHeight);
                 }
             }
             return result;