Printer lookup returns empty on AIX platform due to uninitialized results list

XMLWordPrintable

    • b20
    • aix

        As part of JDK-8344057 ("Remove doPrivileged calls from unix platform sources in the java.desktop module"), changes were made to execCmd() in
        src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java.
        In the updated implementation, execCmd(...) code is missing to initialize the results variable. It declares it as null and then tries to results.add(line), which prevents the results list from being populated with printer names.

        Impact:
        As a result, PrinterJob.lookupPrintServices() and PrintServiceLookup.lookupPrintServices(...) return no print services on AIX platform.

        Reproduction:
        The issue can be reproduced on AIX using the following standalone Java program:

        import java.awt.GraphicsEnvironment;
        import java.awt.print.PrinterJob;
        import javax.print.PrintService;
        import javax.print.PrintServiceLookup;
        import javax.print.DocFlavor;

        public class ListPrinters {
            public static void main(String[] args) {
                System.out.println("Headless mode: " + GraphicsEnvironment.isHeadless());
                System.out.println("OS: " + System.getProperty("os.name"));
                System.out.println("Java version: " + System.getProperty("java.version"));
                System.out.println("Using PrinterJob.lookupPrintServices():");
                PrintService[] jobServices = PrinterJob.lookupPrintServices();
                if (jobServices.length == 0) {
                    System.out.println("No print services found.");
                } else {
                    for (PrintService printer : jobServices) {
                        System.out.println(" - " + printer.getName());
                    }
                }
                System.out.println("Using PrintServiceLookup.lookupPrintServices():");
                PrintService[] lookupServices =
                    PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null);
                if (lookupServices.length == 0) {
                    System.out.println("No print services found.");
                } else {
                    for (PrintService printer : lookupServices) {
                        System.out.println(" - " + printer.getName());
                    }
                }
            }
        }

        Affected File:
        src/java.desktop/unix/classes/sun/print/PrintServiceLookupProvider.java

              Assignee:
              Harshitha Onkar
              Reporter:
              Shruthi Acharya
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: