Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8252446

Screen.getScreens() is empty sometimes

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        ADDITIONAL SYSTEM INFORMATION :
        Win8.1, JDK12, JavaFX 16ea+1

        A DESCRIPTION OF THE PROBLEM :
        This issue has always existed as far as I know and exists on the latest JavaFX 16ea+1.
         
        Because the private method `javafx.stage.Screen.updateConfiguration`
        uses
        ```
                    Screen.screens.clear();
                    Screen.screens.addAll(newScreens);
        ```
        instead of
        ```
                    Screen.screens.setAll(newScreens);
        ```
        changes in the list produce 2 change events, resulting in an invalid intermediate state (empty list after `clear()`). Even worse, list of screens can be empty, provided there is no screen available.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Plug/unplug screen from the system

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Single list change when screen is pluged/unplugged.
        ACTUAL -
        Multiple list changes when screen is plugged/unplugged.

        ---------- BEGIN SOURCE ----------
        import javafx.application.Application;
        import javafx.collections.ListChangeListener.Change;
        import javafx.scene.Scene;
        import javafx.scene.layout.StackPane;
        import javafx.stage.Screen;
        import javafx.stage.Stage;

        class ScreenEvents extends Application {

        public static void main(String[] args) {
        launch(args);
        }

        @Override
        public void start(Stage stage) {

        Screen.getScreens().addListener((Change<?> event) -> {
        System.out.println("");
                                System.out.println(Screen.getPrimary());
        System.out.println(Screen.getScreens().size());
        });

        final StackPane background = new StackPane(); final Scene scene = new Scene(background, 600, 500);
        stage.show();
        }

        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Ignore every second list change event

        FREQUENCY : always


          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  kcr Kevin Rushforth
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: