changeset 5250:b606518bf749

RT-32975: Exception in PlatformImpl.checkIdle with glass thread checks enabled Reviewed-by: art, anthony
author kcr
date Thu, 03 Oct 2013 08:47:08 -0700
parents 98ddce26ad7b
children 26fbef1eb521
files modules/graphics/src/main/java/com/sun/javafx/application/PlatformImpl.java modules/graphics/src/main/java/javafx/application/Platform.java modules/graphics/src/test/java/com/sun/javafx/pgstub/StubToolkit.java modules/graphics/src/test/java/javafx/scene/SceneTest.java
diffstat 4 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/javafx/application/PlatformImpl.java	Thu Oct 03 08:48:00 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/application/PlatformImpl.java	Thu Oct 03 08:47:08 2013 -0700
@@ -387,6 +387,21 @@
     // Check for idle, meaning the last top-level window has been closed and
     // there are no pending Runnables waiting to be run.
     private static void checkIdle() {
+        // If we aren't initialized yet, then this method is a no-op.
+        if (!initialized.get()) {
+            return;
+        }
+
+        if (!isFxApplicationThread()) {
+            // Add a dummy runnable to the runLater queue, which will then call
+            // checkIdle() on the FX application thread.
+            runLater(new Runnable() {
+                @Override public void run() {
+                }
+            });
+            return;
+        }
+
         boolean doNotify = false;
 
         synchronized (PlatformImpl.class) {
--- a/modules/graphics/src/main/java/javafx/application/Platform.java	Thu Oct 03 08:48:00 2013 -0700
+++ b/modules/graphics/src/main/java/javafx/application/Platform.java	Thu Oct 03 08:47:08 2013 -0700
@@ -78,6 +78,8 @@
      * If this method is called from the Preloader or the Application init
      * method, then the Application stop method may not be called.
      *
+     * <p>This method may be called from any thread.</p>
+     *
      * <p>Note: if the application is embedded in a browser, then this method
      * may have no effect.
      */
@@ -96,6 +98,8 @@
      * application calls {@link #exit}.
      * The default value is true.
      *
+     * <p>This method may be called from any thread.</p>
+     *
      * @param implicitExit a flag indicating whether or not to implicitly exit
      * when the last window is closed.
      * @since JavaFX 2.2
@@ -107,6 +111,8 @@
     /**
      * Gets the value of the implicitExit attribute.
      *
+     * <p>This method may be called from any thread.</p>
+     *
      * @return the implicitExit attribute
      * @since JavaFX 2.2
      */
--- a/modules/graphics/src/test/java/com/sun/javafx/pgstub/StubToolkit.java	Thu Oct 03 08:48:00 2013 -0700
+++ b/modules/graphics/src/test/java/com/sun/javafx/pgstub/StubToolkit.java	Thu Oct 03 08:47:08 2013 -0700
@@ -162,6 +162,12 @@
     }
 
     @Override
+    public boolean isFxUserThread() {
+        // Always on the FX app thread
+        return true;
+    }
+
+    @Override
     public void defer(Runnable runnable) {
         runnable.run();
     }
--- a/modules/graphics/src/test/java/javafx/scene/SceneTest.java	Thu Oct 03 08:48:00 2013 -0700
+++ b/modules/graphics/src/test/java/javafx/scene/SceneTest.java	Thu Oct 03 08:47:08 2013 -0700
@@ -36,6 +36,7 @@
 import com.sun.javafx.pgstub.StubScene;
 import com.sun.javafx.sg.prism.NGCamera;
 import com.sun.javafx.tk.Toolkit;
+import javafx.application.Platform;
 import javafx.beans.InvalidationListener;
 import javafx.beans.Observable;
 import org.junit.After;
@@ -136,6 +137,11 @@
      *                          Scene Content Tests                            *
      *                                                                         *
      **************************************************************************/
+    @Test
+    public void isOnFxAppThread() {
+        assertTrue(Platform.isFxApplicationThread());
+    }
+
     @Test(expected=NullPointerException.class)
     public void testNullRoot() {
         Scene scene = new Scene(null);