Skip to content

Commit a67dc32

Browse files
Jm6CnDDXBwFTakSvogella
authored andcommitted
[Cocoa] Fix NPE when the press-and-hold accent menu inserts text
Picking an accent from macOS's press-and-hold menu in a Text, Combo or Spinner with a verify listener failed with a NullPointerException when the click came more than a moment after the key-up. The menu inserts the text from the run loop while Display.sleep runs, so NSApplication.currentEvent() is null, and shouldChangeTextInRange_replacementString called type() on it. Treat a missing event like a non-key event, so that verifyText gets null, as it already does for a mouse event. Fixes #3819 Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 90a9bf5 commit a67dc32

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Combo.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,8 +1848,10 @@ boolean shouldChangeTextInRange_replacementString(long id, long sel, long affect
18481848
if (hooks (SWT.Verify)) {
18491849
String string = new NSString(replacementString).getString();
18501850
NSEvent currentEvent = display.application.currentEvent();
1851-
long type = currentEvent.type();
1852-
if (type != OS.NSKeyDown && type != OS.NSKeyUp) currentEvent = null;
1851+
if (currentEvent != null) {
1852+
long type = currentEvent.type();
1853+
if (type != OS.NSKeyDown && type != OS.NSKeyUp) currentEvent = null;
1854+
}
18531855
String newText = verifyText(string, (int)range.location, (int)(range.location+range.length), currentEvent);
18541856
if (newText == null) return false;
18551857
if (!string.equals(newText)) {

‎bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Spinner.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,8 +1032,10 @@ boolean shouldChangeTextInRange_replacementString(long id, long sel, long affect
10321032
if (hooks (SWT.Verify)) {
10331033
String text = new NSString(replacementString).getString();
10341034
NSEvent currentEvent = display.application.currentEvent();
1035-
long type = currentEvent.type();
1036-
if (type != OS.NSKeyDown && type != OS.NSKeyUp) currentEvent = null;
1035+
if (currentEvent != null) {
1036+
long type = currentEvent.type();
1037+
if (type != OS.NSKeyDown && type != OS.NSKeyUp) currentEvent = null;
1038+
}
10371039
String newText = verifyText(text, (int)range.location, (int)(range.location+range.length), currentEvent);
10381040
if (newText == null) return false;
10391041
if (text != newText) {

‎bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Text.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,8 +2372,10 @@ boolean shouldChangeTextInRange_replacementString(long id, long sel, long affect
23722372
String newText = text;
23732373
if (hooks (SWT.Verify)) {
23742374
NSEvent currentEvent = display.application.currentEvent();
2375-
long type = currentEvent.type();
2376-
if (type != OS.NSKeyDown && type != OS.NSKeyUp) currentEvent = null;
2375+
if (currentEvent != null) {
2376+
long type = currentEvent.type();
2377+
if (type != OS.NSKeyDown && type != OS.NSKeyUp) currentEvent = null;
2378+
}
23772379
newText = verifyText(text, (int)range.location, (int)(range.location+range.length), currentEvent);
23782380
}
23792381
if (newText == null) return false;

0 commit comments

Comments
 (0)