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

Mac: Application processes termination prematurely when a nested event loop is running

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8u40
    • 8u40
    • javafx
    • None

      When an application closes the last stage, a runnable is posted via runLater() which calls Toolkit.exit(). Under most circumstances this works fine because the runnable won't be executed until the current user event handler returns. However, if the event handler causes a nested event loop to get started, the exiting runnable will be executed prematurely which will cause the FX Application Thread check to fail every time the app (or the toolkit) tries to access JavaFX APIs. For example, consider the following code in a user event handler:

         // ...
         myLastVisibleStage.close(); // <--- here the termination runnable will be posted
         Stage newStage = new Stage();
         // blah-blah
         newStage.showAndWait(); // <--- starts a nested event loop

      At this point we come to a situation when the termination runnable starts executing while the application has a visible, live stage shown on the screen. Note that a similar situation could arise if the user code submits some runnables via runLater() after the myLastVisibleStage.close() call, so simply re-checking whether all the windows are gone before proceeding with the termination runnable may not work well.

      To reproduce this bug, please do the following on Mac (this particular case won't work on other platforms):

      1. Modify the HelloFullscreen toy so that it does NOT enter the full screen upon startup by commenting out the setFullScreen(true) call (or simply run the toy as is and press ESC to exit it)
      2. Enter the native full screen mode by clicking the FullScreen button at the upper-right corner of the window title bar (available on OS X 10.7+)
      3. Click the Close button in the full screen scene
      4. Observe exceptions in the console window

      This is happening because when exiting, the native full screen mode is running an internal nested event loop until the full screen exiting operation is complete. And the loop also manages to execute the termination runnable. However, since the actual event handler that caused the termination in the first place hasn't really finished executing yet, it will call other JavaFX methods which will now fail the thread check.

            anthony Anthony Petrov (Inactive)
            anthony Anthony Petrov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: