Skip to content

Commit 87c9a91

Browse files
Fix NPE in MenuItem#calculateRenderSize for non-cascade items
Previously, calculateRenderSize created a GC using getMenu().getShell(), which throws a NullPointerException when the MenuItem has no submenu (e.g., PUSH, CHECK styles). This change replaces getMenu().getShell() with getParent().getShell(), ensuring a valid shell is always used regardless of item type. fixes: #2247
1 parent fc94eaf commit 87c9a91

File tree

1 file changed

+1
-1
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+1
-1
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MenuItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ LRESULT wmMeasureChild (long wParam, long lParam) {
14251425
}
14261426

14271427
private Point calculateRenderedTextSize() {
1428-
GC gc = new GC(this.getMenu().getShell());
1428+
GC gc = new GC(this.getParent().getShell());
14291429
String textWithoutMnemonicCharacter = getText().replace("&", "");
14301430
Point points = gc.textExtent(textWithoutMnemonicCharacter);
14311431
gc.dispose();

0 commit comments

Comments
 (0)