Skip to content

Commit 971b9a6

Browse files
Phillipusmerks
authored andcommitted
[Mac] Fix ClassCastException when selecting a color in FontDialog
- See #1814 - Also use Java 17 instanceof pattern matching in this code block
1 parent 1f67f33 commit 971b9a6

File tree

1 file changed

+8
-7
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets

1 file changed

+8
-7
lines changed

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Display.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5988,9 +5988,10 @@ static long dialogProc(long id, long sel, long arg0) {
59885988

59895989
switch (Selector.valueOf(sel)) {
59905990
case sel_changeColor_: {
5991-
ColorDialog dialog = (ColorDialog)OS.JNIGetObject(jniRef[0]);
5992-
if (dialog == null) return 0;
5993-
dialog.changeColor(id, sel, arg0);
5991+
Object object = OS.JNIGetObject(jniRef[0]);
5992+
if (object instanceof ColorDialog colorDialog) {
5993+
colorDialog.changeColor(id, sel, arg0);
5994+
}
59945995
return 0;
59955996
}
59965997
case sel_changeFont_: {
@@ -6012,10 +6013,10 @@ static long dialogProc(long id, long sel, long arg0) {
60126013
}
60136014
case sel_windowWillClose_: {
60146015
Object object = OS.JNIGetObject(jniRef[0]);
6015-
if (object instanceof FontDialog) {
6016-
((FontDialog)object).windowWillClose(id, sel, arg0);
6017-
} else if (object instanceof ColorDialog) {
6018-
((ColorDialog)object).windowWillClose(id, sel, arg0);
6016+
if (object instanceof FontDialog fontDialog) {
6017+
fontDialog.windowWillClose(id, sel, arg0);
6018+
} else if (object instanceof ColorDialog colorDialog) {
6019+
colorDialog.windowWillClose(id, sel, arg0);
60196020
}
60206021
return 0;
60216022
}

0 commit comments

Comments
 (0)