Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaFX launch failure with ExceptionInInitializerError does not exit normally. #262

Open
dg444 opened this issue Dec 12, 2024 · 0 comments

Comments

@dg444
Copy link

dg444 commented Dec 12, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant