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

To download the current JDK release, click here.
JDK 7
7 b02Fixed
Description
According to the spec for Toolkit.isFrameStateSupported(int state):
Throws:
    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 {
            Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.ICONIFIED);
        } catch (HeadlessException e) {
            if (GraphicsEnvironment.isHeadless()) {
                System.out.println("OKAY: headless thrown correctly");
                return;
            } else {
                System.out.println("headless thrown incorrectly");
                return;
            }
        }
        if (GraphicsEnvironment.isHeadless()) {
            System.out.println("Failed: HeadlessException is not thrown in Headless environment");
            return;
        }
        System.out.println("OKAY");
    }
    public static void main(String[] args) {
        MyHeadlessTest t = new MyHeadlessTest();
        t.case1();
    }
}
=======================================================================

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

Comments
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
20-05-2005

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
20-05-2005