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

Enforce threading restrictions for show and hide methods in Window, Control, and Skin

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • jfx25
    • jfx23
    • javafx
    • None
    • master

      The public and protected "show" and "hide" methods (and related methods like showAndWait, setShowing, close, etc) of Window, Control, and Skin, including their subclasses, should throw an IllegalStageException if called on a thread other than the FX app thread. Some of them already do, but many do not, which can lead to unpredictable failures at runtime. See JDK-8349004 and JDK-8349096 for an example.

      Most JavaFX objects, such as Node and Scene, can be constructed and modified on any thread unless and until that object is attached to a visible Window. Showing or hiding a Window is an operation that must always be done on the JavaFX application thread as documented in the Window and Stage classes.

      The PopupWindow class defines additional show methods that are not documented to throw an exception, but in the cases where they do actually show the window, they will get an exception. Similarly the ContextMenu subclass of PopupWindow defines two more show methods with the same problem.

      Some controls and skins also have operations that will show or hide a popup window. As with the above methods in PopupWindow, some operations can fail, often in hard-to-detect ways, if called on the wrong thread.

      Here is the list of classes whose show and hide methods (and similar) should be documented to throw an exception if called on a thread other than the JavaFX Application Thread, and this restriction should be enforced at runtime:

      Window subclasses:

      javafx.stage.Window
          javafx.stage.Stage
          javafx.stage.PopupWindow
              javafx.scene.control.ContextMenu

      * Control subclasses

      javafx.scene.control.ChoiceBox
      javafx.scene.control.ComboBoxBase
      javafx.scene.control.Dialog
      javafx.scene.control.Menu
      javafx.scene.control.MenuButton

      * Skin subclasses

      javafx.scene.control.skin.ComboBoxBaseSkin
          javafx.scene.control.skin.ComboBoxPopupControl
              javafx.scene.control.skin.ColorPickerSkin
              javafx.scene.control.skin.DatePickerSkin

            angorya Andy Goryachev
            kcr Kevin Rushforth
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: