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

"gradlew run" fails due to MouseHandler hack #95

Closed
Clashsoft opened this issue May 13, 2024 · 1 comment · Fixed by #96
Closed

"gradlew run" fails due to MouseHandler hack #95

Clashsoft opened this issue May 13, 2024 · 1 comment · Fixed by #96
Labels
bug Something isn't working

Comments

@Clashsoft
Copy link
Member

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.

@Clashsoft Clashsoft added the bug Something isn't working label May 13, 2024
@LeStegii
Copy link
Collaborator

LeStegii commented May 13, 2024

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']
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants