fujaba / fulibFx

A framework for JavaFX applications that is designed for MVC pattern projects.
https://fujaba.github.io/fulibFx/
MIT License
2 stars 0 forks source link

"gradlew run" fails due to MouseHandler hack #95

Closed Clashsoft closed 4 months ago

Clashsoft commented 4 months ago

Describe the bug When launching an app using gradlew run, it fails with a cryptic message Exception in Application start method. Changing the catch (Exception e) in App.start to Throwable reveals this:

May 13, 2024 10:54:32 AM de.uniks.stp24.App start
SEVERE: An error occurred while starting the application: null
java.lang.ExceptionInInitializerError
    at org.fulib.fx.util.ControllerUtil.requireControllerProvider(ControllerUtil.java:99)
    at org.fulib.fx.controller.Router.registerRoute(Router.java:74)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
    at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
    at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:1024)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
    at org.fulib.fx.controller.Router.registerRoutes(Router.java:58)
    at org.fulib.fx.FulibFxApp.registerRoutes(FulibFxApp.java:342)
    at de.uniks.stp24.App.start(App.java:39)
    at javafx.graphics@21.0.2/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
    at javafx.graphics@21.0.2/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
    at javafx.graphics@21.0.2/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
    at javafx.graphics@21.0.2/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
    at javafx.graphics@21.0.2/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private javafx.scene.Scene$MouseHandler javafx.scene.Scene.mouseHandler accessible: module javafx.graphics does not "opens javafx.scene" to unnamed module @60b118b5
    at java.base/java.lang.reflect.AccessibleObject.throwInaccessibleObjectException(AccessibleObject.java:391)
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private javafx.scene.Scene$MouseHandler javafx.scene.Scene.mouseHandler accessible: module javafx.graphics does not "opens javafx.scene" to unnamed module @60b118b5

    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:367)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:315)
    at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:183)
    at java.base/java.lang.reflect.Field.setAccessible(Field.java:177)
    at org.fulib.fx.util.ReflectionUtil.<clinit>(ReflectionUtil.java:38)
    ... 20 more

To Reproduce Steps to reproduce the behavior:

  1. gradlew run any app.

Expected behavior No exception.

Additional context The error is a ExceptionInInitializerError because the code fails in the static { } block of the ReflectionUtil class. Thus the catch (Exception e) does not work.

LeStegii commented 4 months ago

This can be fixed by adding the following snippet, which grants unnamed modules access to the javafx module, to the build.gradle of the application:

run {
    jvmArgs = jvmArgs + ['--add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED']
}