United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6273366 Toolkit.isFrameStateSupported(int state) doesn't throw HeadlessException in Headless environment
JDK-6273366 : Toolkit.isFrameStateSupported(int state) doesn't throw HeadlessException in Headless environment

Details
Type:
Bug
Submit Date:
2005-05-19
Status:
Closed
Updated Date:
2011-03-29
Project Name:
JDK
Resolved Date:
2011-03-07
Component:
client-libs
OS:
generic
Sub-Component:
java.awt
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.2
Fixed Versions:

Related Reports

Sub Tasks

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



Hardware and Software, Engineered to Work Together