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

Document that Platform.runLater must not be called before FX is initialized

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8
    • fx2.1
    • javafx
    • JavaFX 2.1b14
      java version "1.6.0_30"
      Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode)
      Win7 64

      In an attempt to reproduce another odd issue with a race condition I managed to "reproduce" something else instead:

      Exception in thread "runLater" java.lang.IllegalStateException: Toolkit not initialized
      at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:121)
      at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:116)
      at javafx.application.Platform.runLater(Platform.java:52)
      at test.swing.FXInitTest$1.run(FXInitTest.java:23)

      Steps to reproduce:
      1. Start the attached application and restart until the exception occurs. I never needed more than 5 starts.

      This is strange. The test uses 5 threads. Each of these creates a JFXPanel and then creates a Button (via runLater). The JFXPanel should only init the toolkit by calling initFX in its constructor which eventually set the initalized flag on PlatformImpl. In spite of that, some threads manage to get to the runLater with initialized still being false.

      The same thing happens if the test code is triggered when a JButton is clicked. This part is not included in the code because there is no difference in the outcome. By the way, creating a JFXPanel seems like a workaround anyway. If this is commented out, Platform.runLater will always fail at the initialized check. See also RT-13289.

            kcr Kevin Rushforth
            wlehmann Werner Lehmann
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: