Skip to content

Commit bef3ad7

Browse files
ShahzaibIbrahimHeikoKlare
authored andcommitted
Fix NPEs in MenuItem#calculateRenderSize() and MenuItem#getMonitorZoom()
Previously, calculateRenderSize() and getMonitorZoom() of MenuItem used getMenu() to get some context providing the relevant shell instead of getParent(). Since that menu may be null when the MenuItem has no submenu (e.g., PUSH, CHECK styles), an NPE might have been thrown. 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 bef3ad7

File tree

1 file changed

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

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ GC createNewGC(long hDC, GCData data) {
12911291
}
12921292

12931293
private int getMonitorZoom() {
1294-
return getMenu().getShell().getMonitor().zoom;
1294+
return getParent().getShell().getMonitor().zoom;
12951295
}
12961296

12971297
private int getMenuZoom() {
@@ -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)