JDK-8304441 : [macos] Crash when putting invalid unicode char on clipboard
  • Type: Bug
  • Component: javafx
  • Sub-Component: window-toolkit
  • Affected Version: jfx11,8,jfx17,jfx20,jfx21
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • Submitted: 2023-03-18
  • Updated: 2023-04-11
  • Resolved: 2023-04-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 Other
8u381Fixed jfx21Fixed
Related Reports
Relates :  
Description
Putting an invalid unicode character on the system clipboard will cause the application to crash with an assertion error. The following is sufficient to provoke the crash:

        int[] codePoints = { 0xD83D };
        String str = new String(codePoints, 0, codePoints.length);
        ClipboardContent c = new ClipboardContent();
        c.put(DataFormat.PLAIN_TEXT, str);
        Clipboard.getSystemClipboard().setContent(c);

To reproduce, run the attached test program:

$ java ClipboardCrash

2023-03-18 06:28:07.771 java[85534:2112820] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Calling -setData:forType: on NSPasteboardItem with nil `data` for type public.utf8-plain-text.'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007ff80a4db40b __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007ff80a027e25 objc_exception_throw + 48
	2   CoreFoundation                      0x00007ff80a4db270 +[NSException raise:format:] + 214
	3   AppKit                              0x00007ff80d8b1d9a -[NSPasteboardItem setData:forType:] + 287
	4   libglass.dylib                      0x0000000107ef4052 Java_com_sun_glass_ui_mac_MacPasteboard__1putItemsFromArray + 1778
	5   ???                                 0x00000001112ee53a 0x0 + 4583253306
)
libc++abi: terminating with uncaught exception of type NSException

Comments
Changeset: 2b2a7f1f Author: Kevin Rushforth <kcr@openjdk.org> Date: 2023-04-06 11:35:22 +0000 URL: https://git.openjdk.org/jfx/commit/2b2a7f1f7cdad676159d471d2fee6025bbf4e939
06-04-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jfx/pull/1074 Date: 2023-03-28 15:09:29 +0000
28-03-2023

This bug only occurs on macOS. The program runs with no errors on Linux and Windows.
18-03-2023