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

Application.runLater throws IllegalStateException if called from ShutdownHook

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8u20
    • 8u20
    • javafx
    • None

    Description

      Starting with Java 8u20, we get this error, when halting the VM:

      Exception in thread "Thread-4" java.lang.IllegalStateException: Attempt to call defer when toolkit not running
      at com.sun.javafx.tk.quantum.QuantumToolkit.defer(QuantumToolkit.java:646)
      at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:285)
      at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:261)
      at javafx.application.Platform.runLater(Platform.java:78)

      I don't see a way to check if the Toolkit is running or not. So the only possibility is to wrap the Platform.runLater call in a try-catch?

      Testcase: Click Button.

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.stage.Stage;

      public class TestApp2 extends Application {
          public static void main(String[] args) {
              Application.launch(args);
          }

          @Override
          public void start(Stage stage) throws Exception {

              Runtime.getRuntime().addShutdownHook(new Thread() {
                  @Override
                  public void run() {
                      Platform.runLater(new Runnable() {
                          @Override
                          public void run() {

                          }
                      });
                  }
              });

              Button button = new Button("Click");
              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      System.exit(0);
                  }
              });

              Scene scene = new Scene(button);
              stage.setScene(scene);
              stage.show();
          }
      }



      I also saw this error, after shutting down the VM, but I can't get to reproduce it with the above Testcase:

      java.lang.NullPointerException
      at com.sun.javafx.tk.quantum.QuantumToolkit.isSupported(QuantumToolkit.java:1044)
      at com.sun.javafx.application.PlatformImpl.isSupportedImpl(PlatformImpl.java:713)
      at com.sun.javafx.application.PlatformImpl.isSupported(PlatformImpl.java:468)
      at javafx.application.Platform.isSupported(Platform.java:163)
      at javafx.scene.Scene.getEffectiveCamera(Scene.java:957)
      at javafx.scene.Scene.pick(Scene.java:1898)
      at javafx.scene.Scene.access$6700(Scene.java:144)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:3673)
        at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3447)
      at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1723)
      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2456)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:348)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:273)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:382)
      at com.sun.glass.ui.View.handleMouseEvent(View.java:553)
        at com.sun.glass.ui.View.notifyMouse(View.java:925)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.lambda$null$126(WinApplication.java:102)
      at com.sun.glass.ui.win.WinApplication$$Lambda$37/33481228.run(Unknown Source)
      at java.lang.Thread.run(Thread.java:745)

      Attachments

        Issue Links

          Activity

            People

              kcr Kevin Rushforth
              cschudtjfx Christian Schudt (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported: