[OpenJDK 2D-Dev] RFR: 8263984: Invalidate printServices when there are no printers

Alexey Ivanov aivanov at openjdk.java.net
Wed Mar 24 20:47:40 UTC 2021

On Wed, 24 Mar 2021 13:07:21 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

> Since this is windows specific code, I am not sure if system will not have any printers. I guess by default, Microsoft XPS Document Writer, Microsoft Print-to-PDF, Fax are present in printers list.

Yes, that's correct. But you can remove them. You can also configure the image so that these are not installed by default.

> That is the reason we do not have getPrintService() return 0 printer although there may not be any real printer present in windows system...reason for some failure in jtreg test which caused us to use `@key printer `tag in those tests to make real printers are configured.

I agree that getting zero printers in Windows is unlikely. But it's still possible.

Consider the following scenario: Let's assume there are 10 printers in the system. The user removes 5 of them. In this case, `invalidateService()` is called on the instances of `Win32PrintService` which were removed from the system.

Then the user removes the remaining 5 printers. In this case, `invalidateService()` is not called at all. If an application has references to any of these instances, they will continue to appear operational. However, the flag `isInvalid` in `Win32PrintService` is used in two methods only: `getPrinterState` and `getPrinterStateReasons`.

This fix is minor, probably this situation never occurs in the real life.

The difference in handling the deleted services caught my attention. If everyone agrees it's not problem, I'll withdraw the PR and close the bug as _Not an Issue_.


PR: https://git.openjdk.java.net/jdk/pull/3151

More information about the 2d-dev mailing list