JDK-8246248 : TransferHandler.exportToClipboard prints stacktrace even if succeeded
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 11,15
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2020-05-25
  • Updated: 2020-09-23
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.
Other
tbdUnresolved
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 10, 64 Bit
Java 11.0.7

A DESCRIPTION OF THE PROBLEM :
This is similar to JDK-6606476.

TransferHandler.exportToClipboard tries to write contents to the clipboard in various formats and DataFlavors. If an exception occurs in one iteration, it is printed to the console and the loop continues.

This is confusing, especially if exporting succeeded for another DataFlavor or another format.
But since the exception is printed and not rethrown, this cannot be controlled by the application.

The experience occurs for JPEG images containing an alpha component, since support for which was dropped in JDK-8204187.
Also, we use ImageIO plugins provided by https://github.com/haraldk/TwelveMonkeys to reenable support for images with an alpha component, but because of the described behavior

Instead of printing the exception on the standard console, the fix replaces printing the stack trace of any exception that may occur while placing data to the clipboard with logging.

FREQUENCY : always



Comments
Have done a fix for the issue. Test case 1: Have tested image with ALPHA component, the exception is not thrown. The clipboard copy operation is successful. The copied image can be pasted in the MSPaint app. Test case 2: Have tested image without ALPHA component, the exception is not thrown. The clipboard copy operation is successful. The copied image can be pasted in the MSPaint app. Also, as per Dmitry's suggestion, I ran the JTReg on ClipBoard and DataTransfer with my fix and without my fix. The result is as below: Without my Fix - test passed 56, 1 failed, 1 error With my Fix - test passed 57, 1 failed, NO error I am also attaching the JTReg report with this.
24-06-2020

Support for images containing an alpha component was dropped in https://bugs.openjdk.java.net/browse/JDK-8204187. The issue is observed when the image being copied onto the clipboard having alpha component in it(which is required for providing transparency). Images may or may not have alpha component in it. Here the copy operation is being performed on the image irrespective of the alpha component. Analysis done: Scenario 1: Tried the same example with the image not having alpha component in it. When the copy button is clicked, the exception is not thrown since the alpha component is not present and also the image got copied onto the clipboard. Got verified by pasting the copied image in MSPaint application. Observation: Exception is not thrown and copy operation is successful. Scenario 2: Tried the same example with the image having alpha component in it. When the copy button is clicked, the exception is thrown since the alpha component is present but, the image got copied onto the clipboard successfully. Got verified by pasting the copied image in MSPaint application. Observation: Exception is thrown and copy operation is successful. So, even though the copy operation is successful on to the clipboard with the image having alpha component, the exception is thrown. This should not be the case. The exception should not be thrown.
19-06-2020

Additional note from submitter: "The code that prints the exception is located in sun.awt.windows.WClipboard.setContentsNative(Transferable)."
02-06-2020

OS: Windows 10 JDK 8u251 Pass JDK 10 Pass JDK 11.0.7 Fail JDK 15ea25 Fail Even though image is successfully copied, the exception is printed on console. This issue occurs for JDK 11 and above, since support for images containing an alpha component was dropped in https://bugs.openjdk.java.net/browse/JDK-8204187. This is a sort of enhancement request to not print the exceptions on console. Moving to dev team for further analysis.
01-06-2020

Requested submitter to provide additional information. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< To understand the issue better, please provide a testcase/reproducer for this.
01-06-2020