8161732: [TEST_BUG] Test closed/java/awt/MenuBar/MenuBarPeer/MenuBarPeerDisposeTest.java fails in unix enviroments with NullPointerException
authorssadetsky
Tue, 17 Jan 2017 18:24:28 +0300
changeset 43230 f139e452dd55
parent 43229 e5d389380a23
child 43231 4885b2a3898b
8161732: [TEST_BUG] Test closed/java/awt/MenuBar/MenuBarPeer/MenuBarPeerDisposeTest.java fails in unix enviroments with NullPointerException Reviewed-by: yan
jdk/src/java.desktop/unix/classes/sun/awt/X11/XMenuBarPeer.java
--- a/jdk/src/java.desktop/unix/classes/sun/awt/X11/XMenuBarPeer.java	Mon Jan 16 16:37:47 2017 +0300
+++ b/jdk/src/java.desktop/unix/classes/sun/awt/X11/XMenuBarPeer.java	Tue Jan 17 18:24:28 2017 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -248,9 +248,11 @@
         XMenuItemPeer.TextMetrics[] itemMetrics = new XMenuItemPeer.TextMetrics[itemCnt];
         for (int i = 0; i < itemCnt; i++) {
             itemMetrics[i] = itemVector[i].getTextMetrics();
-            Dimension dim = itemMetrics[i].getTextDimension();
-            if (dim != null) {
-                maxHeight = Math.max(maxHeight, dim.height);
+            if (itemMetrics[i] != null) {
+                Dimension dim = itemMetrics[i].getTextDimension();
+                if (dim != null) {
+                    maxHeight = Math.max(maxHeight, dim.height);
+                }
             }
         }
         //Calculate bounds
@@ -260,6 +262,9 @@
         for (int i = 0; i < itemCnt; i++) {
             XMenuItemPeer item = itemVector[i];
             XMenuItemPeer.TextMetrics metrics = itemMetrics[i];
+            if (metrics == null) {
+                continue;
+            }
             Dimension dim = metrics.getTextDimension();
             if (dim != null) {
                 int itemWidth = BAR_ITEM_MARGIN_LEFT + dim.width + BAR_ITEM_MARGIN_RIGHT;
@@ -280,9 +285,6 @@
                 Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP + y);
                 nextOffset += itemWidth + BAR_ITEM_SPACING;
                 item.map(bounds, textOrigin);
-            } else {
-                Rectangle bounds = new Rectangle(nextOffset, BAR_SPACING_TOP, 0, 0);
-                Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP);
             }
         }
         XMenuItemPeer mappedVector[] = new XMenuItemPeer[mappedCnt];