Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
8263322: Calling Application.launch on FX thread should throw Illegal…
…StateException, but causes deadlock Reviewed-by: kcr, arapte
- Loading branch information
1 parent
5898858
commit 9796a83
Showing
9 changed files
with
280 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
tests/system/src/test/java/test/com/sun/javafx/application/InitializeJavaFXBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package test.com.sun.javafx.application; | ||
|
||
import javafx.application.Application; | ||
import javafx.stage.Stage; | ||
import junit.framework.Assert; | ||
import test.util.Util; | ||
|
||
public class InitializeJavaFXBase { | ||
|
||
public static class TestApp extends Application { | ||
@Override | ||
public void start(Stage primaryStage) throws Exception { | ||
} | ||
} | ||
|
||
public void doTestInitializeThenLaunchInFX() throws Exception { | ||
Util.runAndWait(() ->{ | ||
try { | ||
Application.launch(TestApp.class); | ||
Assert.fail("Error: No Exception was thrown - expected IllegalStateException"); | ||
} catch (IllegalStateException e) { | ||
// This Exception is what we expect! | ||
} | ||
}); | ||
} | ||
|
||
public void doTestInitializeThenSecondLaunch() throws Exception { | ||
try { | ||
Application.launch(TestApp.class); | ||
Assert.fail("Error: No Exception was thrown - expected IllegalStateException"); | ||
} catch (IllegalStateException e) { | ||
// This Exception is what we expect! | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
tests/system/src/test/java/test/com/sun/javafx/application/InitializeJavaFXLaunch1Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package test.com.sun.javafx.application; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class InitializeJavaFXLaunch1Test extends InitializeJavaFXLaunchBase { | ||
|
||
@BeforeClass | ||
public static void initialize() throws Exception { | ||
InitializeJavaFXLaunchBase.initializeApplicationLaunch(); | ||
} | ||
|
||
@Test (timeout = 15000) | ||
public void testLaunchThenLaunchInFX() throws Exception { | ||
doTestInitializeThenLaunchInFX(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
tests/system/src/test/java/test/com/sun/javafx/application/InitializeJavaFXLaunch2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package test.com.sun.javafx.application; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class InitializeJavaFXLaunch2Test extends InitializeJavaFXLaunchBase { | ||
|
||
@BeforeClass | ||
public static void initialize() throws Exception { | ||
InitializeJavaFXLaunchBase.initializeApplicationLaunch(); | ||
} | ||
|
||
@Test (timeout = 15000) | ||
public void testLaunchThenLaunch() throws Exception { | ||
doTestInitializeThenSecondLaunch(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/system/src/test/java/test/com/sun/javafx/application/InitializeJavaFXLaunchBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package test.com.sun.javafx.application; | ||
|
||
import javafx.application.Application; | ||
import javafx.stage.Stage; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class InitializeJavaFXLaunchBase extends InitializeJavaFXBase { | ||
public static final CountDownLatch appLatch = new CountDownLatch(1); | ||
|
||
public static class InitializeApp extends Application { | ||
@Override | ||
public void start(Stage primaryStage) throws Exception { | ||
appLatch.countDown(); | ||
} | ||
} | ||
|
||
public static void initializeApplicationLaunch() throws Exception { | ||
new Thread(() -> { | ||
Application.launch(InitializeApp.class); | ||
}).start(); | ||
assertTrue(appLatch.await(5, TimeUnit.SECONDS)); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
tests/system/src/test/java/test/com/sun/javafx/application/InitializeJavaFXStartup1Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package test.com.sun.javafx.application; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class InitializeJavaFXStartup1Test extends InitializeJavaFXStartupBase { | ||
|
||
@BeforeClass | ||
public static void initialize() throws Exception { | ||
InitializeJavaFXStartupBase.initializeStartup(); | ||
} | ||
|
||
@Test (timeout = 15000) | ||
public void testStartupThenLaunchInFX() throws Exception { | ||
doTestInitializeThenLaunchInFX(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/system/src/test/java/test/com/sun/javafx/application/InitializeJavaFXStartup2Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package test.com.sun.javafx.application; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class InitializeJavaFXStartup2Test extends InitializeJavaFXStartupBase { | ||
|
||
@BeforeClass | ||
public static void initialize() throws Exception { | ||
InitializeJavaFXStartupBase.initializeStartup(); | ||
} | ||
|
||
@Test (timeout = 15000) | ||
public void testStartupThenLaunch() throws Exception { | ||
|
||
// The first call to Application.launch should work | ||
InitializeJavaFXLaunchBase.initializeApplicationLaunch(); | ||
|
||
doTestInitializeThenSecondLaunch(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/system/src/test/java/test/com/sun/javafx/application/InitializeJavaFXStartupBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package test.com.sun.javafx.application; | ||
|
||
import javafx.application.Platform; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class InitializeJavaFXStartupBase extends InitializeJavaFXBase { | ||
|
||
public static void initializeStartup() throws Exception { | ||
CountDownLatch latch = new CountDownLatch(1); | ||
Platform.startup(() -> { | ||
latch.countDown(); | ||
}); | ||
assertTrue(latch.await(5, TimeUnit.SECONDS)); | ||
} | ||
} |
9796a83
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues