On Fri, 16 Feb 2024 08:46:10 GMT, Christoph Langer <clan...@openjdk.org> wrote:

>> The assertions reported in the bug were observed spuriously and here and 
>> there broke tests in some Windows configurations.
>> For instance [JDK-8266129](https://bugs.openjdk.org/browse/JDK-8266129), 
>> [JDK-8269529](https://bugs.openjdk.org/browse/JDK-8269529) or 
>> [JDK-8323664](https://bugs.openjdk.org/browse/JDK-8323664) came up due to 
>> this.
>> 
>> The problem is that in Windows environments without a valid display, e.g. 
>> started by system services or via PowerShell Remoting, one sees a Monitor 
>> with name 'Windisc' in `EnumDisplayMonitors`.
>> However, it seems to be some kind of a pseudo device where you can not get a 
>> DC via `CreateDC`. This behavior/monitor type doesn't seem to be well 
>> documented, though.
>> 
>> I hereby modify the device initialization code to only count/detect monitors 
>> where CreateDC returns non-NULL in Devices.cpp. I also add some more 
>> checking/error handling to AwtWin32GraphicsDevice::Initialize() for 
>> correctness.
>> 
>> Furthermore, I re-enable the test 
>> `javax/swing/reliability/HangDuringStaticInitialization.java` for Windows 
>> Debug VMs, which reverts the fix from JDK-8269529 that should not be 
>> necessary any more.
>
> Christoph Langer has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Little cleanup

src/java.desktop/windows/native/libawt/windows/Devices.cpp line 93:

> 91: int g_nMonitorCounter;
> 92: int g_nMonitorLimit;
> 93: HMONITOR* g_hmpMonitors;

These global variables — `g_nMonitorCounter`, `g_nMonitorLimit`, 
`g_hmpMonitors` — could be `static` as well.

In fact, they can be encapsulated in the relevant functions which need them by 
using the last parameter of 
[`EnumDisplayMonitors`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumdisplaymonitors).
 For `CountMonitors`, using `&nMonitorCounter` will be enough; for 
`CollectMonitors`, the three variables need to be encapsulated in a local 
structure the pointer to which is passed.

However, it's likely not worth the effort… If it works, don't touch it.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/17614#discussion_r1492345167

Reply via email to