United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-7023011 : Toolkit.getPrintJob(Frame,String,Properties) throws HE instead of specified NPE

Details
Type:
Bug
Submit Date:
2011-02-28
Status:
Closed
Updated Date:
2012-03-22
Project Name:
JDK
Resolved Date:
2011-04-21
Component:
client-libs
OS:
generic
Sub-Component:
java.awt
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Relates:
Relates:

Sub Tasks

Description
JDK: 1.1+
Class: java.awt.Toolkit
Platform: All
Method:
http://download.java.net/jdk7/docs/api/java/awt/Toolkit.html#getPrintJob%28java.awt.Frame,%20java.lang.String,%20java.util.Properties%29

 says:

 Throws:
     NullPointerException - if frame is null. This exception is always thrown when GraphicsEnvironment.isHeadless() returns true.

 This assertion is not satisfied.

 Please compile and execute with "-Djava.awt.headless=true"  the following code sample:

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

import java.awt.*;
import java.util.Properties;

public class NONPE {

    public static void main(String[] args) {
        System.out.println("GraphicsEnvironment.isHeadless() = "
                + GraphicsEnvironment.isHeadless());

        /**
         * @throws  NullPointerException if frame is null.  This exception is
         *          always thrown when GraphicsEnvironment.isHeadless() returns
         *          true.
         */
        Toolkit.getDefaultToolkit().getPrintJob(
                new Frame(), "title", new Properties());
    }
}

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

The output will look:

GraphicsEnvironment.isHeadless() = true
Exception in thread "main" java.awt.HeadlessException
	at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:197)
	at java.awt.Window.<init>(Window.java:532)
	at java.awt.Frame.<init>(Frame.java:420)
	at java.awt.Frame.<init>(Frame.java:385)

                                    

Comments
EVALUATION

Should add separate @throws for HeadlessException.
                                     
2011-03-03
SUGGESTED FIX

http://ccc.sfbay/7023011
                                     
2011-03-03



Hardware and Software, Engineered to Work Together