JDK-7023011 : Toolkit.getPrintJob(Frame,String,Properties) throws HE instead of specified NPE
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-02-28
  • Updated: 2017-05-16
  • Resolved: 2011-04-21
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 b138Fixed
Related Reports
Relates :  
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
SUGGESTED FIX http://ccc.sfbay/7023011
03-03-2011

EVALUATION Should add separate @throws for HeadlessException.
03-03-2011