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

UI thread blocked in confirm and alert handlers when they are called by setTimeout

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 7u15, 8
    • javafx
    • windows 7 64-bit
      mac osx

    • web

      When the webview is directed to page with an alert or confirm in a setTimeout function, the UI thread will be blocked in the call/handle functions that were set in setConfirmHandler or setOnAlert. The dialog box will not be drawn and the program will stop repainting. However, The dialog box responds the keyboard.

      This bug does not manifest in a regular browser.

      JOptionPane works as a temporary fix on Windows as the dialog will be drawn, however though the application will not repaint while the dialog is up.

      The HTML below manifests the bug:
      <html>
      <head>
      <script>
      var x =function(){confirm("message")};
      setTimeout(x,250);
      </script>
      </body>
      </html>

          [JDK-8087445] UI thread blocked in confirm and alert handlers when they are called by setTimeout

          This is not related to FX/Swing interoperability. Here is a minimal reproducer:

          public class Test extends Application {
              public void start(Stage t) {
                  Group g = new Group();
                  final Scene s = new Scene(g);
                  final WebView w = new WebView();
                  g.getChildren().add(w);
                  w.getEngine().setOnAlert(new EventHandler<WebEvent<String>>() {
                      @Override
                      public void handle(WebEvent<String> event) {
                          Stage p = new Stage();
                          p.initOwner(s.getWindow());
                          p.setScene(new Scene(new Group(), Color.RED));
                          p.setWidth(400);
                          p.setHeight(400);
                          p.showAndWait();
          // p.show();
                      }
                  });
                  w.getEngine().loadContent("<html><head><script>"
                          + "var x = function(){alert('message')}; setTimeout(x,500);"
                          + "</script><body></body></html>");
                  t.setScene(s);
                  t.show();
              }

              public static void main(String[] args) {
                  launch(args);
              }
          }

          Note that commented call to p.show(). If showAndWait() is replaced with show(), the hang is not observed. I also noticed that if x() is called from <body onload='x();'>, the hang with showAndWait() is still there, but if onload is replaced with onclick, it isn't. It looks like a webkit issue.

          Artem Ananiev (Inactive) added a comment - This is not related to FX/Swing interoperability. Here is a minimal reproducer: public class Test extends Application {     public void start(Stage t) {         Group g = new Group();         final Scene s = new Scene(g);         final WebView w = new WebView();         g.getChildren().add(w);         w.getEngine().setOnAlert(new EventHandler<WebEvent<String>>() {             @Override             public void handle(WebEvent<String> event) {                 Stage p = new Stage();                 p.initOwner(s.getWindow());                 p.setScene(new Scene(new Group(), Color.RED));                 p.setWidth(400);                 p.setHeight(400);                 p.showAndWait(); // p.show();             }         });         w.getEngine().loadContent("<html><head><script>"                 + "var x = function(){alert('message')}; setTimeout(x,500);"                 + "</script><body></body></html>");         t.setScene(s);         t.show();     }     public static void main(String[] args) {         launch(args);     } } Note that commented call to p.show(). If showAndWait() is replaced with show(), the hang is not observed. I also noticed that if x() is called from <body onload='x();'>, the hang with showAndWait() is still there, but if onload is replaced with onclick, it isn't. It looks like a webkit issue.

          Reproduced with the attached Test.java. The alert "dialog" (the square stage at the center of the screen) is not repainted until resized. When I close it, an exception is thrown:

          Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: com.sun.javafx.tk.quantum.EmbeddedStage cannot be cast to com.sun.javafx.tk.quantum.WindowStage
          at com.sun.javafx.tk.quantum.WindowStage.setVisible(WindowStage.java:410)
          at javafx.stage.Window$10.invalidated(Window.java:747)
          at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:107)
          at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:141)
          at javafx.stage.Window.setShowing(Window.java:784)
          at javafx.stage.Window.hide(Window.java:809)

          Peter Zhelezniakov added a comment - Reproduced with the attached Test.java. The alert "dialog" (the square stage at the center of the screen) is not repainted until resized. When I close it, an exception is thrown: Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: com.sun.javafx.tk.quantum.EmbeddedStage cannot be cast to com.sun.javafx.tk.quantum.WindowStage at com.sun.javafx.tk.quantum.WindowStage.setVisible(WindowStage.java:410) at javafx.stage.Window$10.invalidated(Window.java:747) at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:107) at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:141) at javafx.stage.Window.setShowing(Window.java:784) at javafx.stage.Window.hide(Window.java:809)

          Reproduced with the attached Test.java. The alert "dialog" (the square stage at the center of the screen) is not repainted until resized. When I close it, an exception is thrown:

          Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: com.sun.javafx.tk.quantum.EmbeddedStage cannot be cast to com.sun.javafx.tk.quantum.WindowStage
          at com.sun.javafx.tk.quantum.WindowStage.setVisible(WindowStage.java:410)
          at javafx.stage.Window$10.invalidated(Window.java:747)
          at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:107)
          at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:141)
          at javafx.stage.Window.setShowing(Window.java:784)
          at javafx.stage.Window.hide(Window.java:809)

          Peter Zhelezniakov added a comment - Reproduced with the attached Test.java. The alert "dialog" (the square stage at the center of the screen) is not repainted until resized. When I close it, an exception is thrown: Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: com.sun.javafx.tk.quantum.EmbeddedStage cannot be cast to com.sun.javafx.tk.quantum.WindowStage at com.sun.javafx.tk.quantum.WindowStage.setVisible(WindowStage.java:410) at javafx.stage.Window$10.invalidated(Window.java:747) at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:107) at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:141) at javafx.stage.Window.setShowing(Window.java:784) at javafx.stage.Window.hide(Window.java:809)

            Unassigned Unassigned
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Imported: