[Cocoa] NPE in Text.shouldChangeTextInRange_replacementString when the press-and-hold accent menu inserts text
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
The stack trace points to Text.shouldChangeTextInRange_replacementString in the Cocoa Text implementation. Read the null-event handling shown in the issue and check the surrounding VerifyListener path; reproduce with the provided press-and-hold snippet. Done when selecting an accent after waiting inserts it without throwing a NullPointerException; a linked pull request is already open.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
In a Text with a VerifyListener, picking an accent from macOS's press-and-hold menu (è é ê ë ...) more than about 0.2 s after letting go of the key inserts nothing, and SWT throws a NullPointerException:
java.lang.NullPointerException: Cannot invoke "org.eclipse.swt.internal.cocoa.NSEvent.type()" because "currentEvent" is null
at org.eclipse.swt.widgets.Text.shouldChangeTextInRange_replacementString(Text.java:2375)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:6685)
at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
at org.eclipse.swt.widgets.Widget.callSuper(Widget.java:239)
at org.eclipse.swt.widgets.Widget.insertText(Widget.java:1114)
at org.eclipse.swt.widgets.Control.insertText(Control.java:2102)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:6433)
at org.eclipse.swt.internal.cocoa.OS.objc_msgSend_bool(Native Method)
at org.eclipse.swt.internal.cocoa.NSRunLoop.runMode(NSRunLoop.java:40)
at org.eclipse.swt.widgets.Display.sleep(Display.java:5214)
at PressAndHoldVerifySnippet.main(PressAndHoldVerifySnippet.java:18)
In a standalone program the exception is not caught, so it ends the event loop and the program exits. In the Eclipse workbench it is logged and the "e" stays.
Cause: insertText arrives from the run loop while Display.sleep runs, so NSApplication.currentEvent() returns null. Text.shouldChangeTextInRange_replacementString (Cocoa) then calls type() on it without a null check:
if (hooks (SWT.Verify)) {
NSEvent currentEvent = display.application.currentEvent();
long type = currentEvent.type(); // currentEvent is null here
if (type != OS.NSKeyDown && type != OS.NSKeyUp) currentEvent = null;
newText = verifyText(text, (int)range.location, (int)(range.location+range.length), currentEvent);
}
A click within about 0.2 s works because the key-up is then still the current event. A Text without a VerifyListener never runs this code and takes every click.
To Reproduce
Run with -XstartOnFirstThread. Hold E until the accent menu appears, let go of E, wait about a second, then click an accent such as é.
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class PressAndHoldVerifySnippet {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Text text = new Text(shell, SWT.SINGLE | SWT.BORDER);
text.addVerifyListener(e -> { }); // any verify listener triggers the bug
shell.setSize(300, 80);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
Without the addVerifyListener line, every click inserts the accent.
Expected behavior
The accent replaces the "e", as it does in a Text without a VerifyListener and in native macOS text views such as TextEdit.
Screenshots
None.
Environment:
- Select the platform(s) on which the behavior is seen:
-
- All OS
-
- Windows
-
- Linux
-
- macOS
-
Additional OS info (e.g. OS version, Linux Desktop, etc)
macOS 27.2 (26B123), Apple silicon (arm64), "ABC" input source, press-and-hold enabled (the default;ApplePressAndHoldEnablednot set). -
JRE/JDK version
OpenJDK 25
Version since
Seen on SWT 3.135.0.v20260819-1952 (org.eclipse.swt.cocoa.macosx.aarch64). The same code, without a null check, is still on master.
Workaround (or) Additional context
Suggested fix: check for null before calling type(), so a missing event is treated like a non-key event:
NSEvent currentEvent = display.application.currentEvent();
if (currentEvent != null) {
long type = currentEvent.type();
if (type != OS.NSKeyDown && type != OS.NSKeyUp) currentEvent = null;
}
I'd be happy to open a pull request with this change.
- Ngôn ngữ chính
- Java
- Star
- 202
- Fork
- 206
- Merge trung bình
- 1 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 109
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của eclipse-platform/eclipse.platform.swt
-
[Win32] Table tooltip indexes cell font with subitem -1Có thể đã có người làm @fdesbiens đã nhận 15 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
eclipse-platform/eclipse.platform.swt#3752 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
eclipse-platform/eclipse.platform.swt#3546 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
eclipse-platform/eclipse.platform.swt#3428 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 75/100
eclipse-platform/eclipse.platform.swt#3336 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
eclipse-platform/eclipse.platform.swt#3812 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của eclipse-platform/eclipse.platform.swt
Issue tương tự
-
Type: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
javaoperatorsdk.client.oauth-token has no effect on the Kubernetes clientCó thể đã có người làm @RaphaelFakhri đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
MCP add-on: JSON responses with non-ASCII characters are truncated (wrong Content-Length)Có thể đã có người làm @dhanushbs10 đã nhận hôm nay. Đang mởadd-on bug in:mcp
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Map.Coordinate does not implement proper equalsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởvaadin-map
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
vaadin/flow-components#10586 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
WeReadInstaller writes the launcher database on the main thread at handover (Activity pause timeout)Đang mởbug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100