JDK-8013810 : PrintServiceLookup.lookupPrintServices() does not return consistent result
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 7u21
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2013-04-22
  • Updated: 2017-02-07
  • Resolved: 2017-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 7 JDK 8
7u40Fixed 8 b96Fixed
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_21 " 
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux bisonws0043.infra.local 3.8.5-201.fc18.x86_64 #1 SMP Thu Mar 28 21:01:19 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
PrintServiceLookup.lookupPrintServices() method does not return the same print service implementations if print services where searched by name as if they are not filtered.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Install two printers:  " TestOne "  and  " TestTwo " 
2) Lookup all print services without any filtering AttributeSet
3) Compare the instance class with the one receivend on looking up all found print services by their name.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The implementer class is always the same if filtered or not.
ACTUAL -
The implementer class for the returned PrintService implementation differs if the printer name is not the default.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import sun.print.UnixPrintServiceLookup;

import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.AttributeSet;
import javax.print.attribute.HashAttributeSet;
import javax.print.attribute.standard.PrinterName;

public class GetPrintServices {

  public static void main(String[] args) throws Exception {
    UnixPrintServiceLookup lookup = new UnixPrintServiceLookup();
    for (PrintService service : lookup.getPrintServices(null, null)) {
      PrintService serviceByName = lookupByName(lookup, service.getName());
      if (!service.getClass().equals(serviceByName.getClass())) {
        throw new RuntimeException( " NOK expected:  "  + service + "  got:  "  + serviceByName);
      }
    }
    System.out.println( " Test PASSED " );
  }

  private static PrintService lookupByName(UnixPrintServiceLookup lookup, String name) {
    AttributeSet attributes = new HashAttributeSet();
    attributes.add(new PrinterName(name, null));
    for (PrintService service : lookup.getPrintServices(null, attributes)) {
      return service;
    }
    return null;
  }
}

---------- END SOURCE ----------