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

Copy/paste regression since JDK8 b86


    • Subcomponent:
    • Introduced In Build:
    • Introduced In Version:
    • Resolved In Build:
    • OS:
    • Verification:


      Copy/paste scenario fails in NetBeans since JDK b86 (b85 works fine) from Java editor to Java editor. Very likely it was caused by 96750ebc769b changeset - I have applied these changes to b85 and the problem occurred. Note that it works e.g. from java editor to plain text editor and vice versa.

      Scenario for Netbeans:
      1. Start Netbeans with JDK8 b86 or newer.
      2. Open any class in Java editor
      3. Select some text and press Ctrl+c (note that there is an IO exception printed in log/console)
      4. Press ctrl+v to paste it to the Java editor.
      5. Nothing is pasted, no exception is thrown.

      NOTE that this is NOT reproducible if the system clipboard contain text/x-java data before application (NetBeans) starts - during the startup the entry in textMIMESubtypeCharsetSupport map (see below) is set by this already existing flavor in clipboard as false and the problem does not occur. It means you have to e.g. copy some plain text to the clipboard before you start the app.

      My evaluation:

      Within sun.lwawt.macosx.CClipboard.setContentsNative the method sun.awt.datatransfer.DataTransferer.getFormatsForFlavors is called to get flavors map. For text/x-java content type there are two flavors available (among others) with representative class InputStream and Reader. InputStream is iterated first and flavour.isFlavorTextType() is called -> DataTransferer.doesSubtypeSupportCharset() set new entry in textMIMESubtypeCharsetSupport map: key=text/x-java value=true. With this value set to true also next flavor (Reader class) in DataTransferer.getFormatsForFlavors is added into the flavors map (the flavour.isFlavorTextType() returns true).
      So now there is a flavor with io.Reader representative class in the flavors map and now data for these flavors should be set to clipboard. But for Reader flavor there is an exception because isFlavorCharsetTextType(flavor)=true but isTextFormat(format)=false, see the stack trace:

      java.io.IOException: cannot transfer non-text data as Reader at sun.awt.datatransfer.DataTransferer.translateTransferable(DataTransferer.java:1213) at sun.lwawt.macosx.CDataTransferer.translateTransferable(CDataTransferer.java:131) at sun.lwawt.macosx.CClipboard.setContentsNative(CClipboard.java:76) at sun.awt.datatransfer.SunClipboard.setContents(SunClipboard.java:110) at org.netbeans.NbClipboard$SetContents.run(NbClipboard.java:462) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1432) at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2042)

      The Transferable returned by system clipboard (Clipboard.getContents (requestor)) is a bit strange. It contains a lot of flavors (47). In BasicTextUI.importData() text/x-java Reader flavor is selected as importFlavor and importFlavor.getReaderForText(t) throws an IO exception so no data is imported - nothing is pasted.

      For reference, the original NetBeans bug:


          Issue Links



              • Assignee:
                pchelko Petr Pchelko (Inactive)
                anebuzel Antonín Nebuželský
              • Votes:
                0 Vote for this issue
                5 Start watching this issue


                • Created: