JDK-8153732 : Windows remote printer changes do not reflect in lookupPrintServices()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 7,8,9,10,11
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • Submitted: 2016-04-07
  • Updated: 2023-01-12
  • Resolved: 2018-06-25
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 11 JDK 12 JDK 7 JDK 8 Other
11 b20Fixed 12Fixed 7u241Fixed 8u212Fixed openjdk8u222Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Given a windows environment having local and remote printers. Calls to the invoke method lookupPrintServices() on class PrinterJob or PrintServiceLookup will only show changes in the local printers.

The problem lies on the usage of a windows library call that only captures changes on local printers. A alternate solution would be to react on registry printer changes as described here;

https://blogs.msdn.microsoft.com/hmahrt/2012/04/09/how-to-listen-for-printer-connections/

Comments
One more fix is required to fully address this issue: JDK-8222108.
04-07-2019

Ok, can you post this to the jdk8u mailing list for review? Thanks.
27-05-2019

No. It includes renaming Win32PrintServiceLookup.java to PrintServiceLookupProvider.java, fixing class name, references, and native jni method signatures. Webrev: http://cr.openjdk.java.net/~zgu/JDK-8153732_8u/webrev.00/
25-05-2019

Do you mean that it applies cleanly once filenames are fixed? If so, that's fine and doesn't need further review.
24-05-2019

Fix Request: I would like to backport this change to openjdk 8u. It is part of the Oracle updates as well. The patch does not apply cleanly, where it misses an initial renaming patch.
24-05-2019

There are three follow-up fixes to this bug: JDK-8212202, JDK-8221412, JDK-8221263
09-04-2019

URL: http://hg.openjdk.java.net/jdk/jdk/rev/732a3b600098 User: prr Date: 2018-06-27 17:56:36 +0000
27-06-2018

URL: http://hg.openjdk.java.net/jdk/client/rev/732a3b600098 User: aghaisas Date: 2018-06-25 09:04:01 +0000
25-06-2018

Windows provides *PrinterChangeNotification* functions that provides information about printer status changes of the local printers(subset) but not network printers. Alternatively, Windows provides a way thro' which one can get the network printer status changes by using WMI, RegistryKeyChange combination, which is a slightly complex mechanism. The Windows WMI offers an async and sync method to read thro' registry via the WQL query. The async method is considered dangerous as it leaves open a channel until we close it. But the async method has the advantage of being notified of a change in registry by calling callback without polling for it. The sync method uses the polling mechanism to notify. RegistryValueChange cannot be used in combination with WMI to get registry value change notification because of an error that may be generated because the scope of the query would be too big to handle(at times). Hence an alternative mechanism is choosen via the EnumPrinters by polling for the count of printer status changes(add\remove) and based on it update the printers list(both local and remote printers - superset).
20-06-2018

Issue understood and work in progress to find the solution.
18-05-2018

You could probably submit a patch to 2d dev alias, if you have one ready. We could review it and sponsor it to commit into the workspace.
24-04-2018

Is there anything I could help to get this issue move forward? Seems to me that it's getting moved back all the time...
23-04-2018

I agree that it's sad, that Windows does not provide a other way to be notified of remote printers. Unfortunately is adding/removing of remote printers is not such a low frequency event in our customers case and they are not happy with restarting the VM each time, If we could tell the the print service lookup, to refresh its printer list from externally without having to restart the VM would be very helpful even, when the list update would take while. We did something like this in the past using reflection, but removed it in favour to not calling internal JDK methods. Furthermore those will not be available in the near future with the JDK 9 module system.
12-04-2016

It is a bit sad if Windows provides no other way to be notified of remote printers being added than listening on an imprecise registry update as that sounds somewhat hacky. Given that adding/removing remote printers is a low frequency event, restarting should be a viable workaround.
11-04-2016

Because there is no way to tell the PrintServiceLookup to refresh it's printers I think this is still a bug. I only get all known printers by restarting the VM.
11-04-2016

it seems an enhancement, not a bug
07-04-2016

Initial enhancement request for dynamic printer refresh functionality
07-04-2016