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

Frequent issue Java.awt.print.PrinterException: Invalid name of PrintService

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 7u75
    • client-libs
    • x86
    • windows_2008

      FULL PRODUCT VERSION :
      JVM 1.7.0_21

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft® Windows Server® 2008 Enterprise
      Version 6.0.6002 Service Pack 2 Build 6002

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Our java printing application uses remote printing from Windows 2008 Server, we have configured 40/50 printers (HP, RICOH, EPSON, Canon, Printronix, etc..,) on the server for the demand printing

      A DESCRIPTION OF THE PROBLEM :
      When user prints few hundred reports then we face this exceptions especially if you have more Canon printer queues then the frequency of the issue is very often while your are requesting concurrent print jobs

      net.sf.jasperreports.engine.JRException: java.awt.print.PrinterException: Invalid name of PrintService.
      at net.sf.jasperreports.engine.export.JRPrintServiceExporter.exportReport(JRPrintServiceExporter.java:159)
      at com.ceva.ap.print.invokers.ReportPrinter.directPrinting(ReportPrinter.java:171)
      at com.ceva.ap.print.invokers.ReportPrinter.threadDirectedPrinting(ReportPrinter.java:300)
      at com.ceva.ap.print.core.MainPrinter.printData(MainPrinter.java:900)
      at com.ceva.ap.print.core.MainPrinter.runner(MainPrinter.java:157)
      at com.ceva.ap.print.core.RequestPrinter.printData(RequestPrinter.java:198)
      at com.ceva.ap.print.core.RequestPrinter.run(RequestPrinter.java:97)
      at java.lang.Thread.run(Thread.java:722)

      Caused by: java.awt.print.PrinterException: Invalid name of PrintService.
      at sun.awt.windows.WPrinterJob.setNativePrintService(Native Method)
      at sun.awt.windows.WPrinterJob.setPrintService(WPrinterJob.java:595)
      at net.sf.jasperreports.engine.export.JRPrintServiceExporter.exportReport(JRPrintServiceExporter.java:155)
      ... 7 more

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create few canon print queues in window servers and started to giving concurrent print jobs to the queues from simple jasper report printing multi threaded java applications - easily you can reproduce

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Print queue will print the documents without any failure
      ACTUAL -
      net.sf.jasperreports.engine.JRException: java.awt.print.PrinterException: Invalid name of PrintService.
      at net.sf.jasperreports.engine.export.JRPrintServiceExporter.exportReport(JRPrintServiceExporter.java:159)
      at com.ceva.ap.print.invokers.ReportPrinter.directPrinting(ReportPrinter.java:171)
      at com.ceva.ap.print.invokers.ReportPrinter.threadDirectedPrinting(ReportPrinter.java:300)
      at com.ceva.ap.print.core.MainPrinter.printData(MainPrinter.java:900)
      at com.ceva.ap.print.core.MainPrinter.runner(MainPrinter.java:157)
      at com.ceva.ap.print.core.RequestPrinter.printData(RequestPrinter.java:198)
      at com.ceva.ap.print.core.RequestPrinter.run(RequestPrinter.java:97)
      at java.lang.Thread.run(Thread.java:722)

      Caused by: java.awt.print.PrinterException: Invalid name of PrintService.
      at sun.awt.windows.WPrinterJob.setNativePrintService(Native Method)
      at sun.awt.windows.WPrinterJob.setPrintService(WPrinterJob.java:595)
      at net.sf.jasperreports.engine.export.JRPrintServiceExporter.exportReport(JRPrintServiceExporter.java:155)
      ... 7 more

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Caused by: java.awt.print.PrinterException: Invalid name of PrintService.

      REPRODUCIBILITY :
      This bug can be reproduced often.

      ---------- BEGIN SOURCE ----------
      public long directPrinting() {

      JasperPrint jasperPrint = null;
      JRPrintServiceExporter exporter = null;
      PrinterJob printjob = null;

      ireturn = com.twg.common.config.Rc.PRINTEREXCEPTION;

      try {

           jasperPrint = pd.getJasperprint();
      printjob = PrinterJob.getPrinterJob();

      PrintService[] services = PrintServiceLookup
      .lookupPrintServices(null, null);
      int selectedService = -1;
      for (int i = 0; i < services.length; i++) {
      if (services[i].getName().contains(printer)) {
      selectedService = i;
      break;
      }
      }

      printjob.setPrintService(services[selectedService]);
      PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
      printRequestAttributeSet.add(new Copies(copies));

      exporter = new JRPrintServiceExporter();

      exporter.setParameter(JRExporterParameter.JASPER_PRINT,
      jasperPrint);

      exporter.setParameter(
      JRPrintServiceExporterParameter.PRINT_SERVICE,
      services[selectedService]);

      exporter
      .setParameter(
      JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET,
      services[selectedService].getAttributes());

      exporter
      .setParameter(
      JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET,
      printRequestAttributeSet);

      exporter.setParameter(
      JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG,
      Boolean.FALSE);

      exporter.setParameter(
      JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG,
      Boolean.FALSE);

      exporter.exportReport();
                                      ireturn = com.twg.common.config.Rc.OK;
      } catch (JRException e) {
      e.printStackTrace();
      } catch (Exception e) {
      e.printStackTrace();
      }

      return ireturn;
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      We have to restart our java printing application (Window service restart)

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: