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

UnixPrintJob doesn't handle mediaName vs customTray correctly

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Incomplete
    • Affects Version/s: 7
    • Fix Version/s: 9
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
      2d
    • CPU:
      x86
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      java version "1.7.0_147-icedtea"
      OpenJDK Runtime Environment (IcedTea7 2.0) (7~b147-2.0-1)
      OpenJDK 64-Bit Server VM (build 21.0-b17, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Debian Wheezy 3.0.0-2-amd64 #1 SMP Fri Oct 7 20:48:45 UTC 2011 x86_64 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      The system is linked with a network printer (Brother HL5350DNLT) that works correctly in cups.

      A DESCRIPTION OF THE PROBLEM :
      When printing to a tray (so setting the Tray-option in a printrequest) the printjob sends an invalid argument-list to lpr.

      I've done some testing and debuged the problem to a deep level and I noticed that in com.sun.UnixPrintJob the var mediaName is pre-assigned with a default value. If you check the code in the class, you'll see that this means that this var can never be null and that in the print-method this line will always be executed:
      mOptions = " media="+ customMedia.getChoiceName(); (line 349)

      If you've also selected a tray, then also the line mOptions += " media="+choice; (line 357) is executed.
      This means that mOptions matches something like "media=letter media=Tray2".

      I've checked the documentation (cups) and there is mentioned that
      only 1 of these 2 parameters can be there (or combined with a "," to media=letter,Tray2)
      For more info about these options: http://www.cups.org/documentation.php/options.html

      Note 1: the same could be true for the awt-printing infrastructure (e.g. PSPrintJob)
      Note 2: I've also noticed that other apps pass the tray as "InputSlot=Tray2" to cups but I didn't investigate this any further.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) take a similar printer - a network printer with multiple trays (if possible the same)
      2) create a small app that prints to tray 2
      3) run the app and validate the result

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      check that the printer took a sheet from tray 2 and printed the content
      ACTUAL -
      printer gives an error related to the media-parameters

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
                      //Assign the networkprinter
      PrintService p = Printers.getPrinterByName("HL5350DNLT");

                      //set tray 2 as output
                      MediaTray tray2 = ... //Select tray 2 from the supported attribute list
      PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
      attributes.add(tray2);

                      //Create a print job
      DocPrintJob job = p.createPrintJob();
      job.print(new SimpleDoc("Test", DocFlavor.STRING.TEXT_PLAIN, null), attributes);
      ---------- END SOURCE ----------

        Activity

        Hide
        vdyakov Victor Dyakov added a comment -
        Does it affect JDK 9 ?
        Show
        vdyakov Victor Dyakov added a comment - Does it affect JDK 9 ?
        Hide
        psadhukhan Prasanta Sadhukhan added a comment -
        I tried in jdk9 the following testcase as inspired by the test snippet but I did not get any error from the printer. Did you see any error on the console?

        public class PrintBug {

            public static void main (String [] args) {
            try {

                PrintService[] pservices = PrintServiceLookup.lookupPrintServices(null, null);

                //Acquire Printer
                PrintService printer = null;
                for (PrintService serv: pservices) {
                    System.out.println(serv.toString());
                    if (serv.getName().equals("RICOH-Aficio-MP-5002CMD:PDF,PS,URF")) {
                        printer = serv;
                    }
                }

                if (printer != null) {
                    System.out.println("Found!");


                    //Open File
                    FileInputStream fis = new FileInputStream("/export/PrintBug.java");

                    //Create Doc out of file, autosense filetype
                    Doc pdfDoc = new SimpleDoc(fis, DocFlavor.INPUT_STREAM.AUTOSENSE, null);

                    //Create job for printer
                    DocPrintJob printJob = printer.createPrintJob();

                    //Create AttributeSet
                    PrintRequestAttributeSet pset = new HashPrintRequestAttributeSet();

                    //Add MediaTray to AttributeSet
                    pset.add(MediaTray.MIDDLE);

                   // printJob.printDialog();
                    
                    //Print using Doc and Attributes
                    printJob.print(pdfDoc, pset);

                    //Close File
                    fis.close();

                }

            }
            catch (Throwable t) {
                t.printStackTrace();
            }
            }
        }
        Show
        psadhukhan Prasanta Sadhukhan added a comment - I tried in jdk9 the following testcase as inspired by the test snippet but I did not get any error from the printer. Did you see any error on the console? public class PrintBug {     public static void main (String [] args) {     try {         PrintService[] pservices = PrintServiceLookup.lookupPrintServices(null, null);         //Acquire Printer         PrintService printer = null;         for (PrintService serv: pservices) {             System.out.println(serv.toString());             if (serv.getName().equals("RICOH-Aficio-MP-5002CMD:PDF,PS,URF")) {                 printer = serv;             }         }         if (printer != null) {             System.out.println("Found!");             //Open File             FileInputStream fis = new FileInputStream("/export/PrintBug.java");             //Create Doc out of file, autosense filetype             Doc pdfDoc = new SimpleDoc(fis, DocFlavor.INPUT_STREAM.AUTOSENSE, null);             //Create job for printer             DocPrintJob printJob = printer.createPrintJob();             //Create AttributeSet             PrintRequestAttributeSet pset = new HashPrintRequestAttributeSet();             //Add MediaTray to AttributeSet             pset.add(MediaTray.MIDDLE);            // printJob.printDialog();                          //Print using Doc and Attributes             printJob.print(pdfDoc, pset);             //Close File             fis.close();         }     }     catch (Throwable t) {         t.printStackTrace();     }     } }

          People

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

            Dates

            • Created:
              Updated:
              Resolved:
              Imported:
              Indexed: