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

Printing on disconnected network printer causes NPE

    XMLWordPrintable

    Details

    • Subcomponent:
      2d
    • Resolved In Build:
      b45
    • CPU:
      generic
    • OS:
      windows_xp

      Description

      Run the following test on a disconnected network printer, and it would result to an exception.

      ---------
      import java.awt.*;

      public class BugTest {
      public static void main(String[] args) throws InterruptedException {

      Toolkit toolKit=Toolkit.getDefaultToolkit();
      JobAttributes jobAttributes = new JobAttributes();
      PageAttributes pageAttributes = new PageAttributes();
      PrintJob printJob;
      Graphics graphics;

      //printer name or null (default printer)
      jobAttributes.setPrinter(null);
      jobAttributes.setDialog(JobAttributes.DialogType.NONE);


      printJob =
      toolKit.getPrintJob(new Frame(),"PrintJob",jobAttributes,pageAttributes);

      graphics = printJob.getGraphics();
      graphics.drawString(
      "The document name is EMPTY in the printer spool dialog of Windows",
      100,
      100);

      graphics.drawString(toolKit.getClass().getName(),100,200);
      graphics.drawString(jobAttributes.getClass().getName(),100,250);
      graphics.drawString(pageAttributes.getClass().getName(),100,300);
      graphics.drawString(printJob.getClass().getName(),100,350);
      graphics.drawString(graphics.getClass().getName(),100,400);



      // look at the Document Name in the Windows spool dialog window
      // before it has been printed (after 10 second)
      // or change the printer to offline ...
      Thread.sleep(10000);

      graphics.dispose();
      printJob.end();
      System.exit(0);
      }
      }
      ------------------------------


      OUTPUT:

      Exception in thread "main" java.lang.NullPointerException
              at sun.print.Win32PrintService.initMedia(Win32PrintService.java:367)
              at sun.print.Win32PrintService.getSupportedAttributeValues(Win32PrintSer
      vice.java:1078)
              at sun.print.RasterPrinterJob.updatePageAttributes(RasterPrinterJob.java
      :495)
              at sun.print.RasterPrinterJob.setPrintable(RasterPrinterJob.java:939)
              at sun.print.PrintJob2D.printDialog(PrintJob2D.java:435)
              at sun.awt.windows.WToolkit.getPrintJob(WToolkit.java:579)
              at BugTest.main(BugTest.java:17)
      =====================

      VM crash is reproducible with PrinterJob and PrinterService APIs as well on the Tiger-beta2 PIT build dated 18th Feb' 2004.
      I have attached 2 testcases one for PrinterJob and one for PrintService APIs. VM crash is reproducible with the test mentioned in this bug desc - BugTest.java.

      ###@###.### 2004-03-02

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jgodinez Jennifer Godinez (Inactive)
              Reporter:
              jgodinez Jennifer Godinez (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: