United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7184951 [macosx] Exception at java.awt.datatransfer on headless mode (only in GUI session)
JDK-7184951 : [macosx] Exception at java.awt.datatransfer on headless mode (only in GUI session)

Details
Type:
Bug
Submit Date:
2012-07-18
Status:
Closed
Updated Date:
2012-08-03
Project Name:
JDK
Resolved Date:
2012-08-03
Component:
client-libs
OS:
os_x
Sub-Component:
java.awt
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
7u6
Fixed Versions:
7u6 (b22)

Related Reports
Backport:

Sub Tasks

Description
FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.7.0_06-ea-b19)
Java HotSpot(TM) 64-Bit Server VM (build 23.2-b08, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Darwin macmini-4002-2 11.4.0 Darwin Kernel Version 11.4.0: Mon Apr  9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
1. Try the attached short test in GUI session in headless mode;
java -Djava.awt.headless=true GetF4NTests
2. Get the following exception:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at sun.awt.datatransfer.DataTransferer$1.run(DataTransferer.java:333)
    at sun.awt.datatransfer.DataTransferer$1.run(DataTransferer.java:299)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.awt.datatransfer.DataTransferer.getInstance(DataTransferer.java:345)
    at java.awt.datatransfer.SystemFlavorMap.parseAndStoreReader(SystemFlavorMap.java:392)
    at java.awt.datatransfer.SystemFlavorMap.initSystemFlavorMap(SystemFlavorMap.java:268)
    at java.awt.datatransfer.SystemFlavorMap.getNativeToFlavor(SystemFlavorMap.java:132)
    at java.awt.datatransfer.SystemFlavorMap.getNativesForFlavor(SystemFlavorMap.java:689)
    at java.awt.datatransfer.SystemFlavorMap.getFlavorsForNative(SystemFlavorMap.java:820)
    at GetF4NTests.SystemFlavorMap0016(GetF4NTests.java:20)
    at GetF4NTests.main(GetF4NTests.java:9)
Caused by: java.lang.ClassCastException: sun.awt.HeadlessToolkit cannot be cast to sun.lwawt.macosx.LWCToolkit
    at sun.lwawt.macosx.CToolkitThreadBlockedHandler.<init>(CToolkitThreadBlockedHandler.java:31)
    at sun.lwawt.macosx.CDataTransferer.<init>(CDataTransferer.java:230)
    at sun.lwawt.macosx.CDataTransferer.getInstanceImpl(CDataTransferer.java:94)
    ... 15 more
Exception in thread "main" java.awt.AWTError: Cannot instantiate DataTransferer: sun.lwawt.macosx.CDataTransferer
    at sun.awt.datatransfer.DataTransferer$1.run(DataTransferer.java:336)
    at sun.awt.datatransfer.DataTransferer$1.run(DataTransferer.java:299)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.awt.datatransfer.DataTransferer.getInstance(DataTransferer.java:345)
    at java.awt.datatransfer.SystemFlavorMap.parseAndStoreReader(SystemFlavorMap.java:392)
    at java.awt.datatransfer.SystemFlavorMap.initSystemFlavorMap(SystemFlavorMap.java:268)
    at java.awt.datatransfer.SystemFlavorMap.getNativeToFlavor(SystemFlavorMap.java:132)
    at java.awt.datatransfer.SystemFlavorMap.getNativesForFlavor(SystemFlavorMap.java:689)
    at java.awt.datatransfer.SystemFlavorMap.getFlavorsForNative(SystemFlavorMap.java:820)
    at GetF4NTests.SystemFlavorMap0016(GetF4NTests.java:20)
    at GetF4NTests.main(GetF4NTests.java:9)

Please note that this test is passed when executed in ssh session.

REPRODUCIBILITY :
This bug can be reproduced always.

Affected tests (JCK-runtime-7):
api/java_awt/datatransfer/DataFlavor/index.html#rclass[DataFlavor2010]
api/java_awt/datatransfer/SystemFlavorMap/index.html#GetF4N[SystemFlavorMap0016]
api/java_awt/datatransfer/SystemFlavorMap/index.html#GetF4N[SystemFlavorMap0018]
api/java_awt/datatransfer/SystemFlavorMap/index.html#GetF4N[SystemFlavorMap0019]
api/java_awt/datatransfer/SystemFlavorMap/index.html#SetF4N[SystemFlavorMap0026]
api/java_awt/datatransfer/SystemFlavorMap/index.html#SetN4F[SystemFlavorMap0029]
If this is a TCK-RED it MUST be fixed.  I've asked for JCK (Leonid) to wrk with engineering ASAP - to further evaluate

                                    

Comments
EVALUATION

We are instantiating the CDataTransferer class when in headless mode and it is not ready for that. As a hot fix i propose to safeguard methods that can be called in headless mode with appropriate checks so we are not calling native methods that may throw an exception or undefined in headless.
                                     
2012-07-23



Hardware and Software, Engineered to Work Together