JDK-7107138 : PSPrinterJob doesn't invoke lpr correctly on Linux
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: linux
  • CPU: x86
  • Submitted: 2011-11-01
  • Updated: 2015-11-11
  • Resolved: 2015-11-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
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 filterHL5350DNLT).
This printer is a ps-based printer and is configured in cups correctly (so the options like tray and duplex work when invoked through cups)

A DESCRIPTION OF THE PROBLEM :
The problem is that when I try to submit a printjob to the printer (described in additional config) I always get a message on the printer about "Incorrect size".
When I invoke the printer, I always specify a tray - when I do not specify a tray, tray 1 is always used and the printing works.

I've been debugging this issue for a long time and I came out at sun.print.PSPrinterJob.printExecCmd line 1553 where I could find the code: execCmd[n++] = new String(options);
In the man-page for LPR I could find that options should be passed with the "-o" prefix (like done on line 1573 in the same method and also in UnixPrintJob does this correctly).
But when this is solved, I believe there is still a problem because I couldn't find where "mOptions" (global var in PSPrintJob) is assigned to a correct value.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) take a printer that supports tray-based printing (if possible the same printer)
2) create a small app that uses java.awt.print.PrinterJob to print something to tray 2
3) run the app and validate the result

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
the printer takes a sheet from tray 2 and prints the content on it
ACTUAL -
the printer goes in error-mode with the message "incorrect size".

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
            PrinterJob job = PrinterJob.getPrinterJob()
            job.setPrintService(getPrintService());
            job.setPrintable(printable);

            MediaTray trayNumber = ... //one of the selected trays from the supported attributes list

            PrintRequestAttributeSet reqAttrSet = new HashPrintRequestAttributeSet();
            reqAttrSet.add(trayNumber);

            job.print(reqAttrSet);
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
This workaround is only possible if you own the code that invokes the printjob:
using DocPrintJob printerJob = printService.createPrintJob();	(so the print-features in javax.print)

but this is impossible when using the a framework like JasperReports

Comments
I see now that in both jdk9 and jdk8 we invoke lpr correctly with "-o" prefix http://hg.openjdk.java.net/jdk9/client/jdk/file/3c1ed8084a75/src/java.desktop/share/classes/sun/print/PSPrinterJob.java#l1639 http://hg.openjdk.java.net/jdk8u/jdk8u-dev/jdk/file/0eb62e4a75e6/src/share/classes/sun/print/PSPrinterJob.java#l1625 and this works. Can you please try again?
11-11-2015

Does it affect JDK 9 ?
22-07-2015