JDK-8210759 : Swing interop fails when using a minimal jdk image created with jlink
  • Type: Bug
  • Component: javafx
  • Sub-Component: swing
  • Affected Version: openjfx11
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2018-09-14
  • Updated: 2021-09-15
  • Resolved: 2018-09-21
Related Reports
Duplicate :  
Relates :  
Sub Tasks
JDK-8210790 :  
Description
To reproduce this:

1. Download JDK 11

2. Download or build the openjfx11 jmods

3. Create a custom image using the following:

$ jlink --module-path javafx-jmods-11 --add-modules java.desktop,javafx.swing,javafx.controls --output myjdk

4. BUG: run the attached simple SwingNode application

$ myjdk/bin/java SwingNodeApp

InteropFactory: cannot load com.sun.javafx.embed.swing.newimpl.InteropFactoryN
Exception in Application start method
java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.embed.swing.oldimpl.SwingNodeInteropO (in module javafx.swing) cannot access class sun.swing.JLightweightFrame (in module java.desktop) because module java.desktop does not export sun.swing to module javafx.swing
	at javafx.swing/com.sun.javafx.embed.swing.oldimpl.SwingNodeInteropO.<clinit>(SwingNodeInteropO.java:71)
	at javafx.swing/com.sun.javafx.embed.swing.oldimpl.InteropFactoryO.createSwingNodeImpl(InteropFactoryO.java:42)
	at javafx.swing/javafx.embed.swing.SwingNode.<init>(SwingNode.java:271)
	at SwingNodeApp.start(SwingNodeApp.java:21)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
	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)
	... 1 more
Exception running application SwingNodeApp
Comments
I can confirm that this bug is fixed by JDK-8210092.
21-09-2018

Once JDK-8210092 is fixed, and we confirm that it fixes this bug, I will close this bug as a duplicate of JDK-8210092.
14-09-2018

The javafx.swing module depends on a new jdk.unsupported.desktop module in JDK 11. It declares this as a "static" dependency so that openjfx11 is still capable of running on JDK 10, which doesn't have jdk.unsupported.desktop. Since this is a static dependency, jlink doesn't include it in the module graph. $ myjdk/bin/java --list-modules java.base@11 java.datatransfer@11 java.desktop@11 java.prefs@11 java.xml@11 javafx.base javafx.controls javafx.graphics javafx.swing jdk.unsupported@11 Workaround #1: explicitly add jdk.unsupported.desktop to the list of modules passed to jlink: $ jlink --module-path javafx-jmods-11 --add-modules java.desktop,javafx.swing,javafx.controls,jdk.unsupported.desktop --output myjdk Workaround #2: run jlink with the --bind-services option: $ jlink --bind-services --module-path javafx-jmods-11 --add-modules java.desktop,javafx.swing,javafx.controls --output myjdk This will be fixed in openjfx 12 by JDK-8210092, which will change javafx.swing/module-info.java to "require jdk.unsupported.dekstop" (that is, we will remove the "static" qualifier).
14-09-2018