Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6633656
Votes 63
Synopsis Cross platform print dialog doesn't check for orientation being unsupported.
Category java:classes_2d
Reported Against b04
Release Fixed 7(b28), 6u10(b20) (Bug ID:2159806) , 6-open(b09) (Bug ID:2159894)
State 10-Fix Delivered, Verified, bug
Priority: 4-Low
Related Bugs 6693514 , 6699864 , 6741351
Submit Date 26-NOV-2007
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  customer .
    		* 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)) {
Posted Date : 2007-11-26 04:01:37.0

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.
Posted Date : 2008-02-14 09:34:47.0
Work Around
N/A
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.
Posted Date : 2007-11-26 04:24:42.0

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.
Posted Date : 2008-03-05 17:53:48.0
Comments
  
  Include a link with my name & email   

Submitted On 26-NOV-2007
The issue isn't with the PPD, it is with your IPP parser not handling the noValue value tag, which is now used in CUPS 1.3.4 and higher for the orientation-requested-default value when no default has been set (otherwise auto-orientation for image printing doesn't work...)


Submitted On 26-DEC-2007
Same error on OS X Leopard with the new Java 6 dev. preview...


Submitted On 07-JAN-2008
drlaz
All Java apps (Netbeans, iReport, dbSolo, etc.) are broken on my box with this error.

Let me put it this way: I've invested a lot of time and effort in going to Java and away from M$. But my customers like to print, and without hand-editing their PPD files.


Submitted On 19-JAN-2008
sunburned
I agree with drlaz' post above.  No java apps will print on linux.  This bug appears to be similar in nature to bug 6506286, which is still broken even though it's listed as fixed.  Every Java version from 1.5 on has been unable to print from linux (well, if you were using jvm 1.5x you could hack the  /etc/cups/cupsd.conf and you could print, but nothing in any version of 1.6 will print).  Not even on a Brother HL4070CDW color laser printer with BR-script3 driver that works great from all non-java applications.

I've about had it with java.  Considering that Sun's own java printing examples _do_not_work_, and haven't for some time, I can't see how any developer could responsibly release a java application to clients.  Regressive bugs like this are extremely severe, as the results of any java "update" applied on client installations are a broken app and a bunch of phone calls from frustrated customers -- quite possibly ex-customers.   Printing isn't just important,  it is _vital_.


Submitted On 26-JAN-2008
Hmm, I just copied that code from http://java.sun.com/javase/6/docs/technotes/guides/jps/spec/appendix_2DPrinterJob.fm.html#997825 and compiled it with Sun's JDK 1.6.0_10-ea, and it worked. I accepted all the defaults in the dialogs and it printed just fine. This is on Fedora 7 (x86, 32-bit).


Submitted On 05-FEB-2008
monks
All my customers print using Linux and Cups. They all have the error describe in this bug. Where can I do for bypass this bug? 
I can't test the solution describe in the workaround, or alternative solution, because the error is in class IPPPrintService.java in the package sun.print and there isn't source code public. What can i do? I response on my customer that they don't print because this is a Sun Bug that I can't resolve??


Submitted On 05-FEB-2008
KMTracey
This workaround succeeded for me:

https://bugs.launchpad.net/ubuntu/+source/sun-java6/+bug/156191/comments/18

That is, manually set the orientation for the printer.  


Submitted On 14-FEB-2008
This is my first comment after a few  now and then Java  developements: Now, Java 1.6 update 4 dosn't resolve it, ea _10 also. I dont understand the long resolve time. All Linux apps dosn't print. I like 1.6 with NetBeans for JSR 296 and GUI-Builder, but JSR 296 on W2K have a bug with ip-sockets and GUIs dosn't print under Linux. Go ahead. Pray, consider. Two bugs in two weeks, I dosn't recognize suns developers. But thanks for the works before.


Submitted On 19-MAR-2008
dev_11
I can no longer print at all.  In my case it is not that the printer does not support orientation.  I am getting:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at sun.awt.windows.WPrinterJob.getPrintService(Unknown Source)
	at sun.awt.windows.WPrinterJob.printDialog(Unknown Source)


When I execute:  printDialog();


This worked fine in 1.5 and is now broken in 1.6


Submitted On 03-APR-2008
azun
printing is not possible in Gutsy + jdk 1.6 bt also in Gutsy +jdk 1.5 ; in Eclipse 3.2 the icon printer is shadowed !


Submitted On 07-APR-2008
skpBoise
This work around worked for me as well. I also had to restart my X Session.
ubuntu 7.10 Gnome 
hp 1050 PSC
https://bugs.launchpad.net/ubuntu/+source/sun-java6/+bug/156191/comments/18


Submitted On 08-APR-2008
AndiXng
Please fix that soon. All people that know no workaround (I'm sure that's over 90% are not able to print anything in Linux). I think this must have HIGH priority!


Submitted On 10-APR-2008
mrojasaquino
as some other people have noted in this bug, i think it is no low priority at all, we have a java erp system, and currently we are migrating to all of our internal users to linux (about 120 users) and now they can't print invoices, orders, statements, etc, so for me, as for any user of this kind of system, it is a very high priority bug

thanks


Submitted On 15-APR-2008
yekibud
This is a high priority bug for me as I am using Servoy under Linux to develop a database application for a customer.  The customer needs printing capability.  Things like this make me not want to use Java and Java based tools.


Submitted On 21-APR-2008
just tested with java6_10 build 22.
confirmed to be fixed in this build


Submitted On 02-JUN-2008
FeriW
>just tested with java6_10 build 22.
>confirmed to be fixed in this build

just tested with java6_10 build 24, that is true that the print dialog is shown BUT when we press print button, the printer  process just stopped and did not print anything.







Submitted On 02-JUN-2008
FeriW
>just tested with java6_10 build 22.
>confirmed to be fixed in this build

just tested with java6_10 build 24, that is true that the print dialog is shown BUT when we press print button, the printer  process just stopped and did not print anything.







Submitted On 02-JUN-2008
FeriW
>just tested with java6_10 build 22.
>confirmed to be fixed in this build

just tested with java6_10 build 24, that is true that the print dialog is shown BUT when we press print button, the printer  process just stopped and did not print anything.







Submitted On 02-JUN-2008
FeriW
>just tested with java6_10 build 22.
>confirmed to be fixed in this build

just tested with java6_10 build 24  
on linux mandriva 2008 (kernel version 2.6.24.4-desktop-1mnb) , that is true that the print dialog is shown BUT when we press print button, the printer  process just stopped and did not print anything.







Submitted On 02-JUN-2008
FeriW
>just tested with java6_10 build 22.
>confirmed to be fixed in this build

just tested with java6_10 build 24  
on linux mandriva 2008 (kernel version 2.6.24.4-desktop-1mnb) , that is true that the print dialog is shown BUT when we press print button, the printer  process just stopped and did not print anything.







Submitted On 02-JUN-2008
FeriW
>just tested with java6_10 build 22.
>confirmed to be fixed in this build

just tested with java6_10 build 24  
on linux mandriva 2008 (kernel version 2.6.24.4-desktop-1mnb) , that is true that the print dialog is shown BUT when we press print button, the printer  process just stopped and did not print anything.







Submitted On 02-JUN-2008
FeriW
>just tested with java6_10 build 22.
>confirmed to be fixed in this build

just tested with java6_10 build 24  
on linux mandriva 2008 (kernel version 2.6.24.4-desktop-1mnb) , that is true that the print dialog is shown BUT when we press print button, the printer  process just stopped and did not print anything.







Submitted On 09-SEP-2008
Aurorius
Most of the solutions required you to change the setting using a GUI, for Linux who uses window managers such as Openbox or Fluxbox, can refer to http://www.pikopong.com/blog/2008/09/09/java-printing-fix-for-linux-with-cups/ for solution


Submitted On 11-SEP-2008
jordg
This worked for me after I tried everything else.
Kudos to: 
http://www.pikopong.com/blog/2008/09/09/java-printing-fix-for-linux-with-cups/

<DefaultPrinter Printer>
# Printer configuration file for CUPS v1.3.7
# Written by cupsd on 2008-09-08 11:24
.
.
.
Option orientation-requested 3
</Printer>



PLEASE NOTE: JDK6 is formerly known as Project Mustang