JDK-8146211 : WebView can't alert from a timer
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8u60,9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2015-12-25
  • Updated: 2016-08-08
  • Resolved: 2016-06-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u112Fixed 9Fixed
Related Reports
Cloners :  
Relates :  
Relates :  
Relates :  
Description
Since 8_u60 my code in NetBeans
http://hg.netbeans.org/html4j/file/e390a06dbfac/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXBrwsr.java#l303
that used to open alert/confirm dialogs is broken, if executed as

window.setTimeout(function() { alert('I will yield an error'); }, 1000);

As far as I can say this is a regression as the same code works in JDK7 and in earlier builds in JDK8.

Workarounds aren't easy, as the JavaScript code is supposed to block and wait until alert/confirm is dismissed.
Comments
I confirm that with build java version "1.8.0_112" Java(TM) SE Runtime Environment (build 1.8.0_112-b07) Java HotSpot(TM) 64-Bit Server VM (build 25.112-b07, mixed mode) my AlertInWebView.zip sample works without any issues. Thanks.
08-08-2016

This fix caused the regression in web unit test case and this fix is backout as part of the bug JDK-8160388
27-06-2016

It seems that we might have a design problem given the above. Please file a new bug. We may need to backout this fix and look for a new solution.
27-06-2016

I do see a unit test failure after this change, test.javafx.scene.web.CallbackTest > testDialogs FAILED java.lang.AssertionError: Method onAlert was not called with args: Favorite color?, at org.junit.Assert.fail(Assert.java:91) at test.javafx.scene.web.CallbackTest$TestUI.checkCalled(CallbackTest.java:266) at test.javafx.scene.web.CallbackTest.testDialogs(CallbackTest.java:187) 370 tests completed, 1 failed, 11 skipped :web:test FAILED Also alert should block the current execution and statement after alert should be executed after user presses "ok" in alert dialogue. Refer the new test case(AlertInWebView.java) which adds a statement after alert to confirm the behavior.
27-06-2016

+1
25-06-2016

Changeset: 666b129d7bd0 Author: mbilla Date: 2016-06-25 00:27 +0530 URL: http://hg.openjdk.java.net/openjfx/9-dev/rt/rev/666b129d7bd0
24-06-2016

webrev: http://cr.openjdk.java.net/~mbilla/8146211/webrev.01/ Incorporated the above suggestion by Kevin..
24-06-2016

+1 code works fine, tested on Linux 64
24-06-2016

webrev: http://cr.openjdk.java.net/~mbilla/8146211/webrev.00/ Tested on jdk-9, windows 64 bit with the attached application (AlertInWebView.zip) Fix for JDK-8097469 Introduced the Exception " java.lang.IllegalStateException: showAndWait is not allowed during animation or layout processing " Inorder not to allow nested event loops during Animation/LayoutProcessing. Sometimes Applications can register for input event handler and in webview case (UIClientImpl.java), nested event loop can be allowed and this fix addresses this problem. FIx will first check whether pulse is zero (means nested event loop can be started). If pulse is zero, then immediately handle the event. If pulze is not zero, then we schedule the event during runLater().
24-06-2016

The code looks good. Can you modify the comment to indicate the reason for the runLater, which is to avoid calling the event handler from the pulse? Something like: // If canStartNestedEventLoop is false, then we are in a pulse, so we need to call the event handler from a runLater()
24-06-2016

Tested the attached zip content with 8u40, 8u60 and 9 In 8u60 and 9 -> when i click on "Click me" button, i get another alert and when i close the second alert, i get the exception ""JavaFX Application Thread" java.lang.IllegalStateException: showAndWait is not allowed during animation or layout processing" In 8u40 - when i click close the second alert, i get another alert with content as "Yields an error!" without exception. This issue seems like regression from 8u60.
20-06-2016

I can reproduce it using the attached test case.
20-06-2016

I have replied to Murali on Friday that there is an AlertInWebView.zip attachment, which shall be unziped and then one can execute "ant jfxsa-run" and reproduce the problem just as written in the first comment in this issue.
20-06-2016

Btw. we tried to workaround the problem by overriding `setTimeout` with our own version and using `runLater` before processing the rest of JavaScript. Our patch is available (at https://bugzilla-attachments-257134.netbeans.org/bugzilla/attachment.cgi?id=158661 ), but quite hacky - it would be better to fix this directly in web view.
22-04-2016

Yes, it is quite possible that the fix for JDK-8097469 is such that the exception is now causing a failure. The underlying problem needs to be fixed in WebView.
03-02-2016

In jdk1.8.0_45 the sample project works and shows the second alert dialog from a timer, but it still prints exceptions. Just in this version the exceptions aren't fatal: Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: Nested event loops are allowed only while handling system events at com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:580) at javafx.stage.Stage.showAndWait(Stage.java:463) and on closing the dialog: Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Key not associated with a running event loop: javafx.stage.Stage@34b842aa at com.sun.javafx.tk.quantum.QuantumToolkit.exitNestedEventLoop(QuantumToolkit.java:609) at javafx.stage.Stage.impl_visibleChanged(Stage.java:1200 The wording of the error messages makes me believe this regression might be related to JDK-8097469.
25-12-2015

Sample NetBeans JavaFX project that can be executed as "ant jfxsa-run" and manages to display first alert dialog without problems, but the second one yields: Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: showAndWait is not allowed during animation or layout processing javafx.stage.Stage.showAndWait(Stage.java:464) alertinwebview.AlertInWebView$1.handle(AlertInWebView.java:38) alertinwebview.AlertInWebView$1.handle(AlertInWebView.java:23) com.sun.javafx.webkit.UIClientImpl.lambda$dispatchWebEvent$52 com.sun.javafx.webkit.UIClientImpl.dispatchWebEvent(UIClientImpl.java:98) com.sun.javafx.webkit.UIClientImpl.alert(UIClientImpl.java:157) com.sun.webkit.WebPage.fwkAlert(WebPage.java:2204) com.sun.webkit.Timer.twkFireTimerEvent(Native Method) com.sun.webkit.Timer.fireTimerEvent(Timer.java:83) com.sun.webkit.Timer.notifyTick(Timer.java:64) javafx.scene.web.WebEngine$PulseTimer.lambda$static$45(WebEngine.java:1201) com.sun.javafx.tk.Toolkit.lambda$runPulse$30(Toolkit.java:355) com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:354) com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:381) com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit. com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit. com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method) com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139)
25-12-2015