JDK-6633656 : Cross platform print dialog doesn't check for orientation being unsupported.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 5.0u19,OpenJDK6,6,6u6
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS:
    linux,linux_2.6,linux_suse_sles_11,linux_ubuntu linux,linux_2.6,linux_suse_sles_11,linux_ubuntu
  • CPU: x86
  • Submitted: 2007-11-26
  • Updated: 2012-10-01
  • Resolved: 2011-03-07
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.
Other JDK 6 JDK 7 Other
5.0u19,OpenJDK6Fixed 6u10Fixed 7 b28Fixed OpenJDK6Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Server VM (build 1.6.0_03-b05, mixed mode)

and

java version "1.7.0"
IcedTea Runtime Environment (build 1.7.0-b23)
IcedTea Server VM (build 1.7.0-b23, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux nirvana.limasoftware.net 2.6.23.1-49.fc8 #1 SMP Thu Nov 8 21:41:26 EST 2007 i686 i686 i386 GNU/Linux


EXTRA RELEVANT SYSTEM CONFIGURATION :
Network printer

A DESCRIPTION OF THE PROBLEM :
We got a report to IcedTea bugzilla:
http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=81

Here is a copy from the original report for reference:
-------------
The example code from http://java.sun.com/javase/6/docs/technotes/guides/jps/spec/appendix_2DPrinterJob.fm.html#997825 throws a null pointer exception.

This is with Fedora 8 java-1.7.0-icedtea-devel:

$ javac Print2DPrinterJob.java
$ java Print2DPrinterJob
selected printer hp_LaserJet_1320_series
Exception in thread "main" java.lang.NullPointerException: null attribute
        at
sun.print.IPPPrintService.isAttributeValueSupported(IPPPrintService.java:1176)
        at
sun.print.ServiceDialog$OrientationPanel.updateInfo(ServiceDialog.java:2165)
        at
sun.print.ServiceDialog$PageSetupPanel.updateInfo(ServiceDialog.java:1281)
        at sun.print.ServiceDialog.initPageDialog(ServiceDialog.java:284)
        at sun.print.ServiceDialog.<init>(ServiceDialog.java:261)
        at sun.print.RasterPrinterJob.pageDialog(RasterPrinterJob.java:684)
        at Print2DPrinterJob.<init>(Print2DPrinterJob.java:35)
        at Print2DPrinterJob.main(Print2DPrinterJob.java:62)

If I comment out the calls to PrinterJob.PageDialog() and
PrinterJob.PrintDialog(), the print job goes through without throwing an
exception.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. download the test code from http://java.sun.com/javase/6/docs/technotes/guides/jps/spec/appendix_2DPrinterJob.fm.html#997825
2. javac Print2DPrinterJob.java
3. java Print2DPrinterJob

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Print dialog to appear.
ACTUAL -
The vm exits with a java.lang.NullPointerException.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NullPointerException: null attribute
        at
sun.print.IPPPrintService.isAttributeValueSupported(IPPPrintService.java:1176)
        at
sun.print.ServiceDialog$OrientationPanel.updateInfo(ServiceDialog.java:2165)
        at
sun.print.ServiceDialog$PageSetupPanel.updateInfo(ServiceDialog.java:1281)
        at sun.print.ServiceDialog.initPageDialog(ServiceDialog.java:284)
        at sun.print.ServiceDialog.<init>(ServiceDialog.java:261)
        at sun.print.RasterPrinterJob.pageDialog(RasterPrinterJob.java:684)
        at Print2DPrinterJob.<init>(Print2DPrinterJob.java:35)
        at Print2DPrinterJob.main(Print2DPrinterJob.java:62)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
    import java.io.*;
    import java.awt.*;
    import java.net.*;
    import java.awt.image.*;
    import java.awt.print.*;
    import javax.print.*;
    import javax.print.attribute.*;
    import javax.print.attribute.standard.*;

    public class Print2DPrinterJob implements Printable {

    	public Print2DPrinterJob() {

    		/* Construct the print request specification.
    		* The print data is a Printable object.
    		* the request additonally specifies a job name, 2 copies, and
    		* landscape orientation of the media.
    		*/
    		PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    		aset.add(OrientationRequested.LANDSCAPE);
    		aset.add(new Copies(2));
    		aset.add(new JobName("My job", null));

    		/* Create a print job */
    		PrinterJob pj = PrinterJob.getPrinterJob();
    		pj.setPrintable(this);
    		/* locate a print service that can handle the request */
    		PrintService[] services =
    			PrinterJob.lookupPrintServices();

    		if (services.length > 0) {
    			System.out.println("selected printer " + services[0].getName());
    			try {
    				pj.setPrintService(services[0]);
    				pj.pageDialog(aset);
    				if(pj.printDialog(aset)) {
    					pj.print(aset);
    				}
    			} catch (PrinterException pe) {
    				System.err.println(pe);
    			}
    		}
    	}

    	public int print(Graphics g,PageFormat pf,int pageIndex) {

    		if (pageIndex == 0) {
    			Graphics2D g2d= (Graphics2D)g;
    			g2d.translate(pf.getImageableX(), pf.getImageableY());
    			g2d.setColor(Color.black);
    			g2d.drawString("example string", 250, 250);
    			g2d.fillRect(0, 0, 200, 200);
    			return Printable.PAGE_EXISTS;
    		} else {
    			return Printable.NO_SUCH_PAGE;
    		}
    	}

    	public static void main(String arg[]) {

    		Print2DPrinterJob sp = new Print2DPrinterJob();
    	}
    }


---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I think that the problem is in line 2162 (5 in this snippet) of
sun.print.ServiceDialog class:

1. OrientationRequested or = (OrientationRequested)asCurrent.get(orCategory);
2. if (or == null ||
3.     !psCurrent.isAttributeValueSupported(or, docFlavor, asCurrent)) {
4.
5.     or = (OrientationRequested) psCurrent.
6.                                 getDefaultAttributeValue(orCategory);

What happens is that in line 1 "or" is correctly initialized to the supplied
value (OrientationRequested.LANDSCAPE), but then
psCurrent.isAttributeValueSupported return false, forcing to query a default
value for the OrientationRequested attribute.

getDefaultAttributeValue contains this call:

if (!isAttributeCategorySupported(category)) {
    return null;
}

So it looks to me like a circular reference, the key is not supported, so we
ask for a default value, but we don't have a default value because the key is
not supported.

The following patch should bypass the problem, but it's not tested (b23).

I think a better solution would be to fix this circular reference problem
adding support for OrientationRequested under linux.

------- cut --------

--- openjdk/jdk/src/solaris/classes/sun/print/IPPPrintService.java-orig	2007-11-25 20:26:20.000000000 +0100
+++ openjdk/jdk/src/solaris/classes/sun/print/IPPPrintService.java	2007-11-25 20:26:44.000000000 +0100
@@ -1173,7 +1173,7 @@
                                              DocFlavor flavor,
                                              AttributeSet attributes) {
         if (attr == null) {
-            throw new NullPointerException("null attribute");
+            return false;
         }
         if (flavor != null) {
             if (!isDocFlavorSupported(flavor)) {
This is reproducible on Ubuntu 7.10 and Ubuntu 8.04 using openjdk6. I tried installing the latest CUPS (1.3.5) on Ubuntu 8.04 and the problem did not go away. I also noticed that some of the common attributes such as Orientation and Copies are reported as unsupported. I tested this with Xerox Phaser 5500 and used the ppd files available on xerox.com.

Comments
EVALUATION CUPS changed their default in 1.3.2 to "no value" which is a value we were not expecting. This caused our code to bail out in the loop and so our code was no longer able to see other supported attributes i.e. orientation-requested-supported, copies-supported, etc. This should be fixed by not bailing out of the loop and also make sure that orientation is always a supported attribute category since JDK can render portrait, landscape, and rev-landscape.
05-03-2008

EVALUATION Yep, the return from getDefaultAttributeValue(..) should be checked for null before using it. But a null return implies orientation is unsupported for all DocFlavors, whereas all services that support 2D should support this. So the fix for this should include an analysis and possible fix there too. Also whilst within spec its surprising that the PPD in this case didn't support orientation. Haven't seen that elsewhere so maybe its a PPD bug.
26-11-2007