Hi,
When trying to run a module with a main class that extends
javafx.application.Application, the following exception is thrown by the VM:
Exception in thread "main" java.lang.RuntimeException: Unable to construct
Application instance: class javamodularity.easytext.gui.Main
at
com.sun.javafx.application.LauncherImpl.launchApplication1(javafx.graphics@9-ea/LauncherImpl.java:926)
at
com.sun.javafx.application.LauncherImpl.lambda$launchApplication$140(javafx.graphics@9-ea/LauncherImpl.java:220)
at java.lang.Thread.run(java.base@9-ea/Thread.java:804)
Caused by: java.lang.IllegalAccessException: class
com.sun.javafx.application.LauncherImpl (in module javafx.graphics) cannot
access class javamodularity.easytext.gui.Main (in module
javamodularity.easytext.gui) because module javamodularity.easytext.gui does
not export javamodularity.easytext.gui to module javafx.graphics
at
sun.reflect.Reflection.throwIllegalAccessException(java.base@9-ea/Reflection.java:465)
at
sun.reflect.Reflection.throwIllegalAccessException(java.base@9-ea/Reflection.java:456)
at
sun.reflect.Reflection.ensureMemberAccess(java.base@9-ea/Reflection.java:98)
at
java.lang.reflect.AccessibleObject.slowCheckMemberAccess(java.base@9-ea/AccessibleObject.java:370)
at
java.lang.reflect.AccessibleObject.checkAccess(java.base@9-ea/AccessibleObject.java:362)
at
java.lang.reflect.Constructor.newInstance(java.base@9-ea/Constructor.java:435)
at
com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$146(javafx.graphics@9-ea/LauncherImpl.java:838)
at
com.sun.javafx.application.PlatformImpl.lambda$runAndWait$160(javafx.graphics@9-ea/PlatformImpl.java:351)
at
com.sun.javafx.application.PlatformImpl.lambda$null$158(javafx.graphics@9-ea/PlatformImpl.java:320)
at java.security.AccessController.doPrivileged(java.base@9-ea/Native
Method)
at
com.sun.javafx.application.PlatformImpl.lambda$runLater$159(javafx.graphics@9-ea/PlatformImpl.java:319)
at
com.sun.glass.ui.InvokeLaterDispatcher$Future.run(javafx.graphics@9-ea/InvokeLaterDispatcher.java:96)
This can be solved by adding a (qualified) export in the module-info of the
module I'm trying to run (inspired by the helpful error message, nice!):
exports javamodularity.easytext.gui to javafx.graphics;
However, that's not really a satisfactory solution. Looks like LauncherImpl
also needs to setup a readability relation on-the-fly, with the caveat that the
class extending Application must always be exported by the application
developer for this to work. Is this the solution we can expect, or are there
any other plans for this situation?
Regards,
Sander