Skip to content

Commit 1d45997

Browse files
8256362: JavaFX must warn when the javafx.* modules are loaded from the classpath
Reviewed-by: arapte, pbansal, jvos
1 parent 9dd2058 commit 1d45997

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

modules/javafx.graphics/src/main/java/com/sun/javafx/application/PlatformImpl.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
import com.sun.javafx.tk.TKListener;
3232
import com.sun.javafx.tk.TKStage;
3333
import com.sun.javafx.tk.Toolkit;
34+
import com.sun.javafx.util.Logging;
3435
import com.sun.javafx.util.ModuleHelper;
3536

37+
import java.lang.module.ModuleDescriptor;
3638
import java.lang.reflect.InvocationTargetException;
3739
import java.lang.reflect.Method;
3840
import java.security.AccessControlContext;
@@ -187,6 +189,23 @@ public static void startup(final Runnable r, boolean preventDuplicateCalls) {
187189
return;
188190
}
189191

192+
final Module module = PlatformImpl.class.getModule();
193+
final ModuleDescriptor moduleDesc = module.getDescriptor();
194+
if (!module.isNamed()
195+
|| !"javafx.graphics".equals(module.getName())
196+
|| moduleDesc == null
197+
|| moduleDesc.isAutomatic()
198+
|| moduleDesc.isOpen()) {
199+
200+
String warningStr = "Unsupported JavaFX configuration: "
201+
+ "classes were loaded from '" + module + "'";
202+
if (moduleDesc != null) {
203+
warningStr += ", isAutomatic: " + moduleDesc.isAutomatic();
204+
warningStr += ", isOpen: " + moduleDesc.isOpen();
205+
}
206+
Logging.getJavaFXLogger().warning(warningStr);
207+
}
208+
190209
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
191210
applicationType = System.getProperty("com.sun.javafx.application.type");
192211
if (applicationType == null) applicationType = "";

modules/javafx.graphics/src/main/java/javafx/application/Application.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@
8080
* {@link #stop} method returns or {@link System#exit} is called.
8181
* </p>
8282
*
83+
* <p><b>Note:</b> The JavaFX classes must be loaded from a set of
84+
* named {@code javafx.*} modules on the <em>module path</em>.
85+
* Loading the JavaFX classes from the classpath is not supported.
86+
* See {@link Platform#startup(Runnable) Platform.startup}
87+
* for more information.
88+
*
8389
* <p><b>Deploying an Application as a Module</b></p>
8490
* <p>
8591
* If the {@code Application} subclass is in a named module then that class

modules/javafx.graphics/src/main/java/javafx/application/Platform.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ private Platform() {
9090
* that the JavaFX runtime be started once.
9191
* </p>
9292
*
93+
* <p><b>Note:</b> The JavaFX classes must be loaded from a set of
94+
* named {@code javafx.*} modules on the <em>module path</em>.
95+
* Loading the JavaFX classes from the classpath is not supported.
96+
* A warning is logged when the JavaFX runtime is started if the JavaFX
97+
* classes are not loaded from the expected named module.
98+
* This warning is logged regardless of whether the JavaFX runtime was
99+
* started by calling this method or automatically as described above.
100+
*
93101
* @throws IllegalStateException if the JavaFX runtime is already running
94102
*
95103
* @param runnable the Runnable whose run method will be executed on the

modules/javafx.graphics/src/main/java/module-info.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
* as well as APIs for animation, css, concurrency, geometry, printing, and
3131
* windowing.
3232
*
33+
* <p><b>Note:</b> The JavaFX classes must be loaded from a set of
34+
* named {@code javafx.*} modules on the <em>module path</em>.
35+
* Loading the JavaFX classes from the classpath is not supported.
36+
* See {@link javafx.application.Platform#startup(Runnable) Platform.startup}
37+
* for more information.
38+
*
3339
* @moduleGraph
3440
* @since 9
3541
*/

0 commit comments

Comments
 (0)