JDK-8056236 : ClassCastException: sun.awt.HeadlessToolkit cannot be cast to sun.awt.SunToolkit in headless mode
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8u20,8u25,9
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2014-08-28
  • Updated: 2014-08-28
  • Resolved: 2014-08-28
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
8u25Resolved
Related Reports
Duplicate :  
Relates :  
Description
This is basically an 8u20 mirror of JDK-8055822

For example, the following code throws ClassCastException if run v.s. 8u20b26 (GA) with -Djava.awt.headless=true or even if DISPLAY variable is not set

Tested on Linux

--------------------------------------------------------------------
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.FlavorMap;
import java.awt.datatransfer.SystemFlavorMap;
import java.util.List;

public class SystemFlavorMapTest {

    public static void main(String[] args) {
        FlavorMap fm = SystemFlavorMap.getDefaultFlavorMap();
        SystemFlavorMap sfm = (SystemFlavorMap)fm;
        final List<DataFlavor> flavorsForNative = sfm.getFlavorsForNative("not-for-sure/registered-before");
        System.err.println("flavorsForNative = " + flavorsForNative);
    }
}

--------------------------------------------------------------------

The following tests which exist in _JCK8_

api/java_awt/datatransfer/DataFlavor/index.html#rclass
api/java_awt/datatransfer/SystemFlavorMap/index.html#GetF4N
api/java_awt/datatransfer/SystemFlavorMap/index.html#SetF4N
api/java_awt/datatransfer/SystemFlavorMap/index.html#SetN4F

fail.

See JCK-7303484 for the test logs

This is likely a regression introduced by JDK-8037202



Comments
This bug needs to be fixed in 8u25. Please backport JDK-8051588.
28-08-2014

Initially bug has been found in jdk9: https://bugs.openjdk.java.net/browse/JDK-8051588
28-08-2014