8161732: [TEST_BUG] Test closed/java/awt/MenuBar/MenuBarPeer/MenuBarPeerDisposeTest.java fails in unix enviroments with NullPointerException

Reviewed-by: yan
This commit is contained in:
Semyon Sadetsky 2017-01-17 18:24:28 +03:00
parent 56e387c99e
commit ffab9993d7

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -248,11 +248,13 @@ public class XMenuBarPeer extends XBaseMenuWindow implements MenuBarPeer {
XMenuItemPeer.TextMetrics[] itemMetrics = new XMenuItemPeer.TextMetrics[itemCnt]; XMenuItemPeer.TextMetrics[] itemMetrics = new XMenuItemPeer.TextMetrics[itemCnt];
for (int i = 0; i < itemCnt; i++) { for (int i = 0; i < itemCnt; i++) {
itemMetrics[i] = itemVector[i].getTextMetrics(); itemMetrics[i] = itemVector[i].getTextMetrics();
if (itemMetrics[i] != null) {
Dimension dim = itemMetrics[i].getTextDimension(); Dimension dim = itemMetrics[i].getTextDimension();
if (dim != null) { if (dim != null) {
maxHeight = Math.max(maxHeight, dim.height); maxHeight = Math.max(maxHeight, dim.height);
} }
} }
}
//Calculate bounds //Calculate bounds
int nextOffset = 0; int nextOffset = 0;
int itemHeight = BAR_ITEM_MARGIN_TOP + maxHeight + BAR_ITEM_MARGIN_BOTTOM; int itemHeight = BAR_ITEM_MARGIN_TOP + maxHeight + BAR_ITEM_MARGIN_BOTTOM;
@ -260,6 +262,9 @@ public class XMenuBarPeer extends XBaseMenuWindow implements MenuBarPeer {
for (int i = 0; i < itemCnt; i++) { for (int i = 0; i < itemCnt; i++) {
XMenuItemPeer item = itemVector[i]; XMenuItemPeer item = itemVector[i];
XMenuItemPeer.TextMetrics metrics = itemMetrics[i]; XMenuItemPeer.TextMetrics metrics = itemMetrics[i];
if (metrics == null) {
continue;
}
Dimension dim = metrics.getTextDimension(); Dimension dim = metrics.getTextDimension();
if (dim != null) { if (dim != null) {
int itemWidth = BAR_ITEM_MARGIN_LEFT + dim.width + BAR_ITEM_MARGIN_RIGHT; int itemWidth = BAR_ITEM_MARGIN_LEFT + dim.width + BAR_ITEM_MARGIN_RIGHT;
@ -280,9 +285,6 @@ public class XMenuBarPeer extends XBaseMenuWindow implements MenuBarPeer {
Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP + y); Point textOrigin = new Point(nextOffset + BAR_ITEM_MARGIN_LEFT, BAR_SPACING_TOP + BAR_ITEM_MARGIN_TOP + y);
nextOffset += itemWidth + BAR_ITEM_SPACING; nextOffset += itemWidth + BAR_ITEM_SPACING;
item.map(bounds, textOrigin); 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]; XMenuItemPeer mappedVector[] = new XMenuItemPeer[mappedCnt];