New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java PrintDialog doesn't work with cups on a linux machine, only a NullPointerException: null attribute is received. #2610

Closed
michaelrsweet opened this Issue Nov 26, 2007 · 2 comments

Comments

Projects
None yet
1 participant
@michaelrsweet
Collaborator

michaelrsweet commented Nov 26, 2007

Version: 1.3.4
CUPS.org User: stefan_sitte

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.(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.

@michaelrsweet

This comment has been minimized.

Show comment
Hide comment
@michaelrsweet

michaelrsweet Nov 26, 2007

Collaborator

CUPS.org User: stefan_sitte

Now there is also a bug report in SDN (Sun Developer Network):
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6633656

Collaborator

michaelrsweet commented Nov 26, 2007

CUPS.org User: stefan_sitte

Now there is also a bug report in SDN (Sun Developer Network):
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6633656

@michaelrsweet

This comment has been minimized.

Show comment
Hide comment
@michaelrsweet

michaelrsweet Nov 26, 2007

Collaborator

CUPS.org User: mike

This is a known bug in Java - basically their IPP implementation makes many assumptions about what will be returned in an IPP request and doesn't handle the "no value" value of orientation-requested. As a result, it stops processing the IPP response (without producing an error/exception about it) and bombs in the print dialog instead.

Please contact Sun for assistance in this Java bug.

Collaborator

michaelrsweet commented Nov 26, 2007

CUPS.org User: mike

This is a known bug in Java - basically their IPP implementation makes many assumptions about what will be returned in an IPP request and doesn't handle the "no value" value of orientation-requested. As a result, it stops processing the IPP response (without producing an error/exception about it) and bombs in the print dialog instead.

Please contact Sun for assistance in this Java bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment