JDK-8193355 : Getting NullPointerException in RasterPrinterJob class while accessing the print () of Printable interface
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: other
  • CPU: x86
  • Submitted: 2017-12-08
  • Updated: 2017-12-12
  • Resolved: 2017-12-12
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 10

A DESCRIPTION OF THE PROBLEM :
Getting NullPointerException while accessing the Print method of RasterPrinterJob Class

xception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at java.desktop/sun.print.RasterPrinterJob.setAttributes(RasterPrinterJob.java:1240)
	at java.desktop/sun.awt.windows.WPrinterJob.setAttributes(WPrinterJob.java:696)
	at java.desktop/sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1510)
	at java.desktop/sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1443)
	at com.test.HelloWorldPrinter.actionPerformed(HelloWorldPrinter.java:70)

REGRESSION.  Last worked in version 8u151

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
public void actionPerformed(ActionEvent e) {
         PrinterJob job = PrinterJob.getPrinterJob();
         job.setPrintable(this);
         boolean ok = job.printDialog();
         if (ok) {
             try {
                  job.print();
             } catch (PrinterException ex) {
              /* The job did not successfully complete */
             }
         }
    }

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should start printing the page as the print command is given.
ACTUAL -
Getting NullPointerException while accessing the Print method of RasterPrinterJob Class

xception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at java.desktop/sun.print.RasterPrinterJob.setAttributes(RasterPrinterJob.java:1240)
	at java.desktop/sun.awt.windows.WPrinterJob.setAttributes(WPrinterJob.java:696)
	at java.desktop/sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1510)
	at java.desktop/sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1443)
	at com.test.HelloWorldPrinter.actionPerformed(HelloWorldPrinter.java:70)

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Getting NullPointerException while accessing the Print method of RasterPrinterJob Class

xception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at java.desktop/sun.print.RasterPrinterJob.setAttributes(RasterPrinterJob.java:1240)
	at java.desktop/sun.awt.windows.WPrinterJob.setAttributes(WPrinterJob.java:696)
	at java.desktop/sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1510)
	at java.desktop/sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1443)
	at com.test.HelloWorldPrinter.actionPerformed(HelloWorldPrinter.java:70)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public void actionPerformed(ActionEvent e) {
         PrinterJob job = PrinterJob.getPrinterJob();
         job.setPrintable(this);
         boolean ok = job.printDialog();
         if (ok) {
             try {
                  job.print();
             } catch (PrinterException ex) {
              /* The job did not successfully complete */
             }
         }
    }
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
public void actionPerformed(ActionEvent e) {
         PrinterJob job = PrinterJob.getPrinterJob();
         job.setPrintable(this);
         boolean ok = job.printDialog();
         if (ok) {
             try {
                  job.print();
             } catch (PrinterException ex) {
              /* The job did not successfully complete */
             }
         }
    }

SUPPORT :
YES


Comments
Reopening based upon additional information provided by the submitter: ========================== Ran the attached and received the same error on WINDOWS OS 10. Similar results appeared with ECLIPSE IDE OXYGEN 1a. and Command prompt also. Attached the screenshot of both. Also attached is the screenshot of printer Configuration which shows that the printer is ready to take the next job of printing. The issue is reproducible across different PC's. Also checked another bug opened in Oracle site regarding the same issue and in that it is mentioned that this bug will be fixed in above JDK 9. But getting the same error in JDK 9, JDK 9.0.1, JDK 10-ea-B34. Below is the link to another report: https://bugs.openjdk.java.net/browse/JDK-8186987 =========================================
12-12-2017

Reported with: JDK 9.0.1 Windows 10 According to report, NPE is received while accessing the Print method of RasterPrinterJob class. When checked with the attached test case, couldn't reproducd the issue with the reported as well as ea versions. Clicking pm Print Hello World always print the page without any exception thrown. (see attached screenshot for reference) Results: ========= 9: OK 9.0.1: OK 10: OK Rechecking with the submitter if the issue is reproducible constantly when run from command line as well as an IDE.
12-12-2017