-
Notifications
You must be signed in to change notification settings - Fork 27
Description
I've setup and run the sample HelloFX app using JDK23+JavaFX23 (same with EA JDK24+JavaFX24). If there is a runtime issue in the static initialisation, the error is reported but JVM does not exit normally - I assume JavaFX non-daemon threads are running.
Demonstrate this by running the following class with and without "-DHelloFX.crash=" in the command line:
// OK - stack trace + exit:
// java --module-path yourmods;C:\java\javafx-sdk-23\lib -m mymodule/HelloFX
// Fail - stack trace and locks VM:
// java --module-path yourmods;C:\java\javafx-sdk-23\lib -DHelloFX.crash= -m mymodule/HelloFX
public class HelloFX extends Application {
static {
if (System.getProperty("HelloFX.crash") != null)
throw new java.lang.ExceptionInInitializerError("HelloFX.crash");
}
public static void main(String[] args) {
Application.launch(HelloFX.class, args);
}
@Override
public void start(Stage stage) {
String javaVersion = System.getProperty("java.version");
String javafxVersion = System.getProperty("javafx.version");
Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
Scene scene = new Scene(new StackPane(l), 640, 480);
stage.setScene(scene);
stage.show();
}
}
Add another class calling the same main(), and all is fine - ie there is a failure as expected and JVM exits:
public class LaunchHelloFX {
static {
if (System.getProperty("LaunchHelloFX.crash") != null)
throw new java.lang.ExceptionInInitializerError("LaunchHelloFX.crash");
}
public static void main(String[] args) {
HelloFX.main(args);
}
}
// OK - stack trace + exit:
// java --module-path yourmods;C:\java\javafx-sdk-23\lib -m mymodule/LaunchHelloFX
// OK - stack trace + exit:
// java --module-path yourmods;C:\java\javafx-sdk-23\lib -DHelloFX.crash= -m mymodule/LaunchHelloFX
Expected result for all launches should be stack trace and JVM exit:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1164)
Caused by: java.lang.ExceptionInInitializerError: HelloFX.crash
at fxexample/HelloFX.(Unknown Source)
at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1161)
at java.base/jdk.internal.reflect.MethodHandleAccessorFactory.ensureClassInitialized(MethodHandleAccessorFactory.java:340)
at java.base/jdk.internal.reflect.MethodHandleAccessorFactory.newMethodAccessor(MethodHandleAccessorFactory.java:71)
at java.base/jdk.internal.reflect.ReflectionFactory.newMethodAccessor(ReflectionFactory.java:154)
at java.base/java.lang.reflect.Method.acquireMethodAccessor(Method.java:726)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at javafx.graphics@23/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics@23/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)