JDK-6273366 : Toolkit.isFrameStateSupported(int state) doesn't throw HeadlessException in Headless environment
  • Type: Bug
  • Status: Closed
  • Resolution: Fixed
  • Component: client-libs
  • Sub-Component: java.awt
  • Priority: P3
  • Affected Version: 1.4.2
  • OS: generic
  • CPU: generic
  • Submit Date: 2005-05-19
  • Updated Date: 2011-03-29
  • Resolved Date: 2011-03-07
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 Availabitlity Release.

To download the current JDK release, click here.
7 b02Fixed
According to the spec for Toolkit.isFrameStateSupported(int state):
    HeadlessException - if GraphicsEnvironment.isHeadless() returns true.

But when running the following code in Headless environment, the method doesn't throw HeadlessException:

import java.awt.*;
public class MyHeadlessTest {
    public void case1() {
        try {
        } catch (HeadlessException e) {
            if (GraphicsEnvironment.isHeadless()) {
                System.out.println("OKAY: headless thrown correctly");
            } else {
                System.out.println("headless thrown incorrectly");
        if (GraphicsEnvironment.isHeadless()) {
            System.out.println("Failed: HeadlessException is not thrown in Headless environment");
    public static void main(String[] args) {
        MyHeadlessTest t = new MyHeadlessTest();

I was running the code with the following command on Solaris:
java -Djava.awt.headless=true MyHeadlessTest

And the result of running the above code is:
Failed: HeadlessException is not thrown in Headless environment

Problem happens on both the Solaris and Linux, and on both the J2SE 1.4.2 and J2SE 1.5.

###@###.### 2005-05-19 22:19:19 GMT

SUGGESTED FIX --- Toolkit.java Fri May 20 15:31:37 2005 *************** *** 1461,1466 **** --- 1461,1469 ---- public boolean isFrameStateSupported(int state) throws HeadlessException { + if (GraphicsEnvironment.isHeadless()){ + throw new HeadlessException(); + } if (this != Toolkit.getDefaultToolkit()) { return Toolkit.getDefaultToolkit(). isFrameStateSupported(state); ###@###.### 2005-05-20 11:34:58 GMT

EVALUATION It's easily reproducible on all platforms. There is no code that support HE throwing. It also haven't done in XToolkit, XWM. Possible solution is to put to rights implementation with the spec by explicit throw operator in Toolkit.java. ###@###.### 2005-05-20 11:34:58 GMT