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

Using clipboard in Shebang-line class prints two log messages to the console

XMLWordPrintable

    • generic
    • os_x

      ADDITIONAL SYSTEM INFORMATION :
      java version "21.0.5" 2024-10-15 LTS
      Java(TM) SE Runtime Environment (build 21.0.5+9-LTS-239)
      Java HotSpot(TM) 64-Bit Server VM (build 21.0.5+9-LTS-239, mixed mode, sharing)

      Mac OSX 15.0.1

      A DESCRIPTION OF THE PROBLEM :
      Using the SystemClipboard in a program run with the shebang line produces output that includes two log messages as the program exits.

      This worked properly under Mac OSX 14.x. This started after upgrading to 15.0.1 in both Java 17 and Java 21. (I don't know if this happened under Java 21 when using Mac OSX 14.x.)

      REGRESSION : Last worked in version 11.0.25

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a file call ToPlain, with the text given in the source-code field.
      2. make it executable: chmod a+x ToPlain
      3. In some other application, copy some text to the clipboard.
      4. Run ToPlain from the command prompt.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The program should copy the text from the clipboard, remove all text formatting, and put the plain text version back on the clipboard. You may verify this by pasting it into another application. The program should print out the plain text, which is now the contents of the clipboard, before exiting.
      ACTUAL -
      After printing out the contents of the clipboard, as the program terminates, it prints these two lines out to the output:
      2024-10-26 04:08:29.170 java[3313:4722690] +[IMKClient subclass]: chose IMKClient_Legacy
      2024-10-26 04:08:29.170 java[3313:4722690] +[IMKInputSession subclass]: chose IMKInputSession_Legacy

      ---------- BEGIN SOURCE ----------
      #!/usr/bin/java --source 17


      import java.awt.Toolkit;
      import java.awt.datatransfer.Clipboard;
      import java.awt.datatransfer.DataFlavor;
      import java.awt.datatransfer.StringSelection;
      import java.awt.datatransfer.UnsupportedFlavorException;
      import java.io.IOException;


      public enum ToPlain {
        ;
        public static void main(String[] args) throws IOException, UnsupportedFlavorException {
          Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
          String text = clipboard.getData(DataFlavor.stringFlavor).toString();
          StringSelection stringSelection = new StringSelection(text);
          clipboard.setContents(stringSelection, stringSelection);
          System.out.println(text);
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      No workaround

      FREQUENCY : always


            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: