JDK-8024987 : Copy/paste regression since JDK8 b86
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8
  • Priority: P1
  • Status: Closed
  • Resolution: Fixed
  • OS: os_x
  • Submitted: 2013-09-18
  • Updated: 2015-01-15
  • Resolved: 2013-09-25
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
8 b110Fixed
Related Reports
Relates :  
Relates :  
Description
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:

crtl+c
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)

ctrl+v
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:
https://netbeans.org/bugzilla/show_bug.cgi?id=230061
Comments
Verified in jdk8b114 Os X 10.9 x64 Testcase: 1. Install jdk 8 b114 on OS X from dmg file 2. Install latest stable Netbeans build (7.4) 3. Reboot os (for clearing clipboard) 3. Start Netbeans 4. Open one java class, select some text, press cmd+c (instead of ctrl+c) 5. Open other java class, press cmd+v (insted of ctrl+v) Result: Copied text pasted
08-11-2013

Hard to create a regression test because the issue is only reproducible inside netbeans
04-10-2013

This is indeed a regression of the fix for JDK-7075105. The refactoring of the SystemFlavorMap class causes this issue, so the possible fix would be to revert a part of that fix.
19-09-2013

The issue is reproducible with the latest build.
18-09-2013