[cups.bugs] [HIGH] STR #2610: java PrintDialog doesn't work with cups on a linux machine, only a NullPointerException: null attribute is received.
Stefan Sitte
stefan.sitte at comsoft.de
Mon Nov 26 09:52:38 PST 2007
DO NOT REPLY TO THIS MESSAGE. INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.
[STR New]
Problem:
Java-Print-Dialog doesn't work with the current cups realease (1.3.4)
because of the following NullPointerException:
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:2164)
at
sun.print.ServiceDialog$PageSetupPanel.updateInfo(ServiceDialog.java:1280)
at sun.print.ServiceDialog.updatePanels(ServiceDialog.java:454)
at sun.print.ServiceDialog.initPrintDialog(ServiceDialog.java:212)
at sun.print.ServiceDialog.<init>(ServiceDialog.java:141)
at javax.print.ServiceUI.printDialog(ServiceUI.java:206)
at sun.print.RasterPrinterJob.printDialog(RasterPrinterJob.java:880)
at sun.print.PSPrinterJob.printDialog(PSPrinterJob.java:440)
at Main.main(Main.java:7)
When i execute following cource code (open only a java print dialog), i
get the NullPointerException.
import java.awt.print.PrinterJob;
public class Main {
public static void main(String[] args) {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.printDialog();
}
}
My system:
KDE version: 3.5.8-7.fc8
Release: 2.6.23.1-49.fc8
Machine: i686
used java versions (with all the same problem):
jdk1.5.0_09
jdk1.6.0_01
jdk1.6.0_03
jdk1.6.0_10
jdk1.7.0
Cups:
Version: 1.3.4
Release: 2.fc8
The exception is caused by a missing orientation attribute. The
ServiceDialog wants to get the attribute, doesn't find the
orientation-attribute and then asks for the default-orientation-attribute,
but the orientation-attribute is not supported by the printers.
code form ServiceDialog:2119:
public void updateInfo() {
//...
OrientationRequested or =
(OrientationRequested)asCurrent.get(orCategory);
if (or == null ||
!psCurrent.isAttributeValueSupported(or, docFlavor, asCurrent)) {
or =
(OrientationRequested)psCurrent.getDefaultAttributeValue(orCategory);
// need to validate if default is not supported
//----------------------------------------------------------------------------------------
// this call throws the NullPointerException, because: or is null
if (!psCurrent.isAttributeValueSupported(or, docFlavor, asCurrent)) {
//----------------------------------------------------------------------------------------
or = null;
Object values =
psCurrent.getSupportedAttributeValues(orCategory,
docFlavor,
asCurrent);
if (values instanceof OrientationRequested[]) {
OrientationRequested[] orValues =
(OrientationRequested[])values;
if (orValues.length > 1) {
// get the first in the list
or = orValues[0];
}
}
}
if (or == null) {
or = OrientationRequested.PORTRAIT;
}
asCurrent.add(or);
}
//...
}
I searched for the problem and found that in the function
IPPPrintService::readIPPResponse() where the attributes are achieved from
a sun.net.www.protocol.http.HttpURLConnection:http://localhost:631/KM3050
(KM3050 is the name of a printer on my system), but the returned
attribute-set does not contain a orientation attribute.
In my mind, the problem depends on cups because it doesn't send any
orientation attribute.
Annotation:
- on windows (without cups) the java print dialog works just fine.
- with a attribute set param for the printdialog it is just the same
result
PrinterJob printJob = PrinterJob.getPrinterJob();
PrintRequestAttributeSet prnSet = new HashPrintRequestAttributeSet();
prnSet.add(MediaSizeName.ISO_A4);
prnSet.add(OrientationRequested.LANDSCAPE);
if (printJob.printDialog(prnSet) == false) {
return;
}
- "update" to older cups releases is no option
I apologize for my "bad" english but it's not my native language.
Link: http://www.cups.org/str.php?L2610
Version: 1.3.4
More information about the cups-devel
mailing list