Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8278908

[macOS] Unexpected text normalization on pasting from clipboard

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 19
    • 17, 18, 19
    • client-libs
    • macOS 12.1

    • b08
    • os_x

      When text is pasted from macOS system clipboard to a Java application, it is always converted to an NFC Unicode normalization form. This is unexpected, as it doesn't happen on pasting to native applications. To reproduce, open the attached sample.txt file in TextEdit, copy its contents to clipboard (Cmd+A, Cmd+C), then launch the following sample application:
      ==============
      import java.awt.*;
      import java.awt.datatransfer.DataFlavor;

      public class ClipboardTest {
          public static void main(String[] args) throws Exception {
              String content = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor);
              for (int i = 0; i < content.length(); i++) {
                  System.out.println(Integer.toHexString(content.charAt(i)));
              }
          }
      }
      ==============
      Expected output (decomposed form, matching sample.txt file's content):
      61
      308

      Actual output (composed form):
      e4

      The issue cannot be observed when pasting from TextEdit to another native macOS application, e.g. to Xcode (the same applies to copying from Xcode to TextEdit).

        1. sample.txt
          0.0 kB
          Dmitry Batrak

            dbatrak Dmitry Batrak
            dbatrak Dmitry Batrak
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: