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