0

I have a very old Swing-based java app that ran fine on Java 8 and I'm trying to switch to Java 11. It relies on JavaFX.

I downloaded OpenJDK 11.0.11_9 JRE and the closest corresponding OpenJFX (11.0.2). I run the project with the necessary --add-module additions to avoid NoClassDefFound errors.

The application seems to work fine, but stderr spews many exceptions like this:

Exception in thread "JavaFX Application Thread" java.lang.IllegalAccessError: class com.sun.javafx.embed.swing.oldimpl.JFXPanelInteropO (in module javafx.swing) cannot access class sun.awt.SunToolkit (in module java.desktop) because module java.desktop does not export sun.awt to module javafx.swing
        at javafx.swing/com.sun.javafx.embed.swing.oldimpl.JFXPanelInteropO.postEvent(JFXPanelInteropO.java:38)
        at javafx.swing/javafx.embed.swing.JFXPanel.invokeOnClientEDT(JFXPanel.java:938)
        at javafx.swing/javafx.embed.swing.JFXPanel.access$400(JFXPanel.java:135)
        at javafx.swing/javafx.embed.swing.JFXPanel$HostContainer.setCursor(JFXPanel.java:1029)
        at javafx.graphics/com.sun.javafx.tk.quantum.EmbeddedScene.setCursor(EmbeddedScene.java:427)
        at javafx.graphics/javafx.scene.Scene$MouseHandler.updateCursorFrame(Scene.java:3984)
        at javafx.graphics/javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2534)
        at javafx.graphics/com.sun.javafx.tk.Toolkit.lambda$runPulse$2(Toolkit.java:412)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at javafx.graphics/com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:411)
        at javafx.graphics/com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:438)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:519)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:499)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:492)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(QuantumToolkit.java:320)
        at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
        at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
        at java.base/java.lang.Thread.run(Unknown Source)

Presumably there is some mechanism to run legacy code like mine and it is not working in this case?

My project imports a variety of javax.swing.* pacakges and a variety of javafx.* packages.

Is there something I can tweak in the code to fix this? Or does the problem have to do with my JRE setup? I'm hoping to avoid any serious refactoring.

user272901
  • 103
  • 6
  • Since you're using JavaFX 11.0.2, and not JavaFX 11.0.11, I assume you have an LTS subscription for Java but not for JavaFX. In that case, try using the latest version of JavaFX—version 16—to see if the error goes away. Note that JavaFX 11-16 are all (cross?)-compiled to Java 11 and so JavaFX 16 should run on Java 11.0.11_9. – Slaw May 18 '21 at 01:52
  • Thanks - tried it and got a new error that said jdk.unsupported.desktop was missing. This didn't bode well maybe?: https://github.com/adoptium/adoptium-support/issues/12 ... but based on a link there I tried the Liberica distribution (which includes javafx) and that is working except for a single startup error "InteropFactory: cannot load com.sun.javafx.embed.swing.newimply.InteropFactoryN"... I only heard of Liberica just now so I'm not sure what the implications/licensing around that are, but checking it out... any further advice welcome! – user272901 May 18 '21 at 05:39
  • Update: yeah, Liberica is working out great. I'd be happy to be educated on what was going wrong above, but it looks like OpenJDK/OpenJFX interaction might be kind of a quagmire. – user272901 May 18 '21 at 21:14

0 Answers0