import javax.print.PrintService; 
import javax.print.PrintServiceLookup; 

public class JavaPrintBug { 

    public static void main(String[] args) { 
        // returns an empty array unless a user has opened system printer settings 
        // only short time ago or an adminstrator has set cupsctl WebInterface=yes 
        PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); 
        System.out.println("Number of printers available: " + printServices.length); // zero 
         
         
        // returns null unless a user has opened system printer settings only 
        // short time ago or an adminstrator has set cupsctl WebInterface=yes 
        PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService(); 
        if(null != defaultPrintService) { // will not be entered 
            System.out.println("Default printer: " + defaultPrintService.getName()); 
        } 
         
        // before entering this loop make sure that NO user has opened system 
        // printer settings only short time ago and NO administrator has set 
        // cupsctl WebInterface=yes (hWebInterface=no)! 
        while(null == PrintServiceLookup.lookupDefaultPrintService()) { 
            // while trapped in here, open system printer settings or set 
            // cupsctl WebInterface=yes and the loop will be left. 
        } 
        System.out.println("Workaround worked!"); 
    } 
} 