5

I got a java.lang.IllegalAccessError because of using a com.sun.* class in Java >9. The solution to this is to add --add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls. I'm not sure how to add this to my build.gradle, but I put

run {
    jvmArgs = ['--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls']
}

into it and it didn't help. This is pretty much the issue I have. The error message is:

java.lang.IllegalAccessError: class org.controlsfx.control.textfield.AutoCompletionBinding (in unnamed module @0x2d7444bc) cannot access class com.sun.javafx.event.EventHandlerManager (in module javafx.base) because module javafx.base does not export com.sun.javafx.event to unnamed module @0x2d7444bc
    at org.controlsfx.control.textfield.AutoCompletionBinding.<init>(AutoCompletionBinding.java:522) ~[controlsfx-11.0.0.jar:11.0.0]
    at impl.org.controlsfx.autocompletion.AutoCompletionTextFieldBinding.<init>(AutoCompletionTextFieldBinding.java:107) ~[controlsfx-11.0.0.jar:11.0.0]
    at org.controlsfx.control.textfield.TextFields.bindAutoCompletion(TextFields.java:151) ~[controlsfx-11.0.0.jar:11.0.0]
[…]
    at java.lang.Thread.run(Thread.java:835) [?:?]
piegames
  • 975
  • 12
  • 31

1 Answers1

12

It looks like you don't have a modular project. There are two options to solve it:

  • Make a modular project

If you add a module-info descriptor, like:

module hellofx {
    requires javafx.controls;
    requires org.controlsfx.controls;

    exports org.openjfx;
}

(adding your modules there, of course), it will work with:

run {
    jvmArgs = ['--add-exports= \
                javafx.base/com.sun.javafx.event=org.controlsfx.controls']
}
  • Export to all modules

Since your project is not modular, it is part of the so called unnamed module. Therefore, you should use ALL-UNNAMED, so the package is exported to all the modules, including ControlsFX:

run {
    jvmArgs = ['--add-exports=javafx.base/com.sun.javafx.event=ALL-UNNAMED']
}
José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • I'm getting the same error which is referred to java.net.http does not export jdk.internal.net.http.common. I've added `run { jvmArgs = ['--add-exports=java.net.http/jdk.internal.net.http=ALL-UNNAMED'] }` but I'm still getting the same error. what am I doing wrong? – Hasti May 31 '21 at 20:26