As noted in the bug report, we get a pair of change events every time the list of screens changes. First, a change is sent with an empty list of screens and then a change is sent with the new list of screens. This happens whenever a monitor is plugged in or unplugged. It also happens on Mac at application startup.
As noted in the bug the reason for this is because the `updateConfiguration` method makes two separate calls on the list of screens, `clear` and `addAll`, rather than calling `setAll`. The latter ensures that only a single change event is delivered. I verified that before this fix, the example program attached to the bug works correctly after the fix. I wrote a unit test. It ends up being skipped on Windows and Linux since we don't get an initial change event. On Mac the test fails without the fix and passes with the fix. ------------- Commit messages: - 8252446: Screen.getScreens() is empty sometimes Changes: https://git.openjdk.java.net/jfx/pull/295/files Webrev: https://webrevs.openjdk.java.net/?repo=jfx&pr=295&range=00 Issue: https://bugs.openjdk.java.net/browse/JDK-8252446 Stats: 107 lines in 2 files changed: 103 ins; 2 del; 2 mod Patch: https://git.openjdk.java.net/jfx/pull/295.diff Fetch: git fetch https://git.openjdk.java.net/jfx pull/295/head:pull/295 PR: https://git.openjdk.java.net/jfx/pull/295