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

IllegalStateException when calling Platform.exit()

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: fx2.0
    • Fix Version/s: None
    • Component/s: javafx
    • Environment:

      Windows 7 64bit, Java 7 b144 EA 32bit, JavaFX 2.0 b30

      Description

      When calling Platform.exit() from a MenuItem, JavaFX 2.0 (b30) issues the following error :
      java.lang.IllegalStateException: Not on FX application thread; currentThread = JavaFX Application Thread
      at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:189)
      at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:321)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:1942)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:1931)
      at javafx.scene.Scene$MouseHandler.access$1000(Scene.java:1904)
      at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1005)
      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:1551)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:154)
      at com.sun.glass.ui.View.handleMouseEvent(View.java:257)
      at com.sun.glass.ui.View.notifyMouse(View.java:514)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
      at com.sun.glass.ui.win.WinApplication$1$1.run(WinApplication.java:49)
      at java.lang.Thread.run(Thread.java:722)
      Exception in thread "JavaFX Application Thread"


      This exception should not be thrown as we are in the JavaFX Application Thread.
      The application still exits after the exception is thrown.

      Sample code:

      public class Main extends Application {

          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              Application.launch(Main.class, args);
          }

          @Override
          public void start(Stage primaryStage) {
              // Construct GUI.
              MenuItem exitItem = new MenuItemBuilder().id("exitItem").text("Exit").build();
              exitItem.setOnAction(new EventHandler<ActionEvent>() {

                  @Override
                  public void handle(ActionEvent event) {
                      exit(0);
                  }
              });
              Menu fileMenu = new MenuBuilder().id("fileMenu").text("File").build();
              fileMenu.getItems().addAll(exitItem);
              Menu editMenu = new MenuBuilder().id("editMenu").text("Edit").build();
              Menu viewMenu = new MenuBuilder().id("viewMenu").text("View").build();
              Menu helpMenu = new MenuBuilder().id("helpMenu").text("Help").build();
              MenuBar menuBar = new MenuBarBuilder().id("menuBar").build();
              menuBar.getMenus().addAll(fileMenu, editMenu, viewMenu, helpMenu);
              ////////////////////////////////////////////////////////////
              primaryStage.setTitle("Hello World");
              BorderPane root = new BorderPane();
              root.setTop(menuBar);
              Scene scene = new Scene(root, 300, 250, Color.LIGHTGREEN);
              primaryStage.setScene(scene);
              primaryStage.setVisible(true);
          }
          
          public void exit(int errorCode) {
              Platform.exit();
          }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              morris Morris Meyer (Inactive)
              Reporter:
              fbouyajfx Fabrice Bouyé (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported: