Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8193355

Getting NullPointerException in RasterPrinterJob class while accessing the print () of Printable interface

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      other

      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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                psadhukhan Prasanta Sadhukhan
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: