JDK-8032693 : javax.print.PrintService does not find any CUPS-Printers on Linux
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • Submitted: 2014-01-24
  • Updated: 2014-07-29
  • Resolved: 2014-02-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.
JDK 8 JDK 9
8u20Fixed 9 b06Fixed
Description
FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.8.0-ea-b124)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b66, mixed mode)

(this also happened with build 1.8.0-ea-b123)

ADDITIONAL OS VERSION INFORMATION :
Linux 3.11.0-15-generic #23-Ubuntu SMP Mon Dec 9 18:17:04 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
No LSB modules are available.
Distributor ID: Ubuntu
  Description:    Ubuntu 13.10
  Release:        13.10
Codename:       saucy


EXTRA RELEVANT SYSTEM CONFIGURATION :
ii  cups                                1.7.0~rc1-0ubuntu5.2   amd64

A DESCRIPTION OF THE PROBLEM :
When trying to print to a CUPS-Printer using JDK 1.8EA the PrintService will not find any Printer. Other Versions of Java (1.6, 1.7) will find and list them.

I used the Test-Program from Bug #6181488:
----------------  Services_getStatus.java ------------------------
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;

public class Services_getStatus {
     public static void main(String[] args){

     PrintService defServ = PrintServiceLookup.lookupDefaultPrintService();
     System.out.println("Default PrintService: "+defServ);

     PrintService[] serv = PrintServiceLookup.lookupPrintServices(null, null);
     if (serv.length==0) {
         System.out.println("no PrintService  found");
     } else {
         System.out.println("number of Services "+serv.length);
     }


     for (int i = 0; i<serv.length ;i++) {
         PrintServiceAttributeSet psa = serv[i].getAttributes();
         System.out.println("printer name "+(i+1)+" "+psa.get(PrinterName.class));
         System.out.println("accepting "+psa.get(PrinterIsAcceptingJobs.class));
     }

     }
}
-----------------------

-- Output with JDK1.8 --

Default PrintService: null
no PrintService  found

-----------------------

-- Output with JDK 1.7 --

Default PrintService: null
number of Services 6
printer name 1 hp2055
accepting accepting-jobs
printer name 2 hp2055
accepting accepting-jobs
printer name 3 Kopierer
accepting accepting-jobs
printer name 4 Kopierer
accepting accepting-jobs
printer name 5 LaserJet
accepting accepting-jobs
printer name 6 LaserJet
accepting accepting-jobs



REGRESSION.  Last worked in version 7u51

ADDITIONAL REGRESSION INFORMATION:
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile Code from above and run
java Services_getStatus
on a Linux-Machine with CUPS-Printers

or try to print from an Application like NetBeans (7.4)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A list of CUPS-Printers
(Note: due to Bug #6181488 the Default-Printer is null)
Default PrintService: null
number of Services 6
printer name 1 hp2055
accepting accepting-jobs
printer name 2 hp2055
accepting accepting-jobs
printer name 3 Kopierer
accepting accepting-jobs
printer name 4 Kopierer
accepting accepting-jobs
printer name 5 LaserJet
accepting accepting-jobs
printer name 6 LaserJet
accepting accepting-jobs

ACTUAL -
Default PrintService: null
no PrintService  found


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;

public class Services_getStatus {
     public static void main(String[] args){

     PrintService defServ = PrintServiceLookup.lookupDefaultPrintService();
     System.out.println("Default PrintService: "+defServ);

     PrintService[] serv = PrintServiceLookup.lookupPrintServices(null, null);
     if (serv.length==0) {
         System.out.println("no PrintService  found");
     } else {
         System.out.println("number of Services "+serv.length);
     }


     for (int i = 0; i<serv.length ;i++) {
         PrintServiceAttributeSet psa = serv[i].getAttributes();
         System.out.println("printer name "+(i+1)+" "+psa.get(PrinterName.class));
         System.out.println("accepting "+psa.get(PrinterIsAcceptingJobs.class));
     }

     }
}

---------- END SOURCE ----------
Comments
With help from the submitter I was able to see what happened. It was introduced by the JDK 8 b115 fix for https://bugs.openjdk.java.net/browse/JDK-8022536 The root of the issue is that if you do not have a default printer set in CUPS then we get an NPE at line 635 (original file) of UnixPrintServiceLookup.java de-referencing the array returned from CUPSPrinter.getDefaultPrinter(). This caused a failure not just locating the default but *any* printer because the NPE went all the way back up to javax.print implementation where it calls getPrintServices() The workaround would be to add a default printer - I would suppose this to be the common case anyway.
07-02-2014

I don't know why this is a problem for the submitter but the program works for me on Ubuntu 13.04 with b124 & b125 :- jdk8b125/bin/java Services_getStatus Default PrintService: IPP Printer : HP-CP4520 number of Services 2 printer name 1 HP-CP4520 accepting accepting-jobs printer name 2 xerox accepting accepting-jobs The first of these printers is local on a USB port and the second is remote on the network via lpd protocol .. So this isn't completely broken and there must be a configuration issue. Therefore I need to know more about how the user's printers are configured on the system. The /etc/cups/printers.conf file would be a good start. In addition I'd like to know which build introduced this There haven't been many JDk 8 changes that seem like they could affect this b12: https://bugs.openjdk.java.net/browse/JDK-6604109 b96: https://bugs.openjdk.java.net/browse/JDK-8013810 [ I don't think this can be it, since it was backported to 7u40 and the submitter doesn't see a problem with 7u51] b115: https://bugs.openjdk.java.net/browse/JDK-8022536 There's also this one but that was to fix a ClassCastException from the b115 fix b119: https://bugs.openjdk.java.net/browse/JDK-8028584 The earliest JDK build I can see on java.net is this one :- https://jdk8.java.net/archive/8-b96.html So that would be good to try whilst its still there Oops b95 is missing but b94 is there so that can be tried: https://jdk8.java.net/archive/8-b94.html In general it seems quite a few of the old builds are there if you just follow that pattern.
24-01-2014

Need more info
24-01-2014

Phil , please evaluate it seems deferrable
24-01-2014