Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8202277

WebView image capture fails with standalone FX due to dependency on javafx.swing



    • Bug
    • Status: Resolved
    • P2
    • Resolution: Fixed
    • jfx11, 8, 9, 10
    • jfx11
    • javafx
    • web



        The javafx.web module has a reflective dependency on the javafx.swing module. The UIClientImpl.toBufferedImage method calls a SwingFXUtils method in javafx.swing, via reflection, to convert an FX image into a BufferedImage. We need to eliminate this dependency.

        To reproduce, run the attached program as follows using OpenJDK 10 + a build of the JavaFX standalone SDK.


        1. Set your JAVA_HOME and PATH to an OpenJDK 10 or 10.0.1 build. Verify this as follows:

        $ java -version
        openjdk version "10" 2018-03-20
        OpenJDK Runtime Environment 18.3 (build 10+46)
        OpenJDK 64-Bit Server VM 18.3 (build 10+46, mixed mode)

        2. Apply the patch from JDK-8198329 to a local clone of jfx-dev

        $ cd $JFX_ROOT/rt
        <apply patch>

        3. Build the standalone FX SDK:

        $ cd $JFX_ROOT/rt
        $ gradle sdk

        4. Run the attached test program with the following options, which should be sufficient:

        $ java --module-path="$JFX_ROOT/rt/build/sdk/lib" --add-modules=javafx.web CanvasTest

        You will get the following exception:

        java.lang.ClassNotFoundException: javafx.embed.swing.SwingFXUtils
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:291)
        at javafx.web/com.sun.javafx.webkit.UIClientImpl.toBufferedImage(UIClientImpl.java:401)
        at javafx.web/com.sun.javafx.webkit.prism.PrismImage.toData(PrismImage.java:68)
        at javafx.web/com.sun.javafx.webkit.prism.PrismImage.toDataURL(PrismImage.java:92)
        at javafx.web/com.sun.webkit.Timer.twkFireTimerEvent(Native Method)
        at javafx.web/com.sun.webkit.Timer.fireTimerEvent(Timer.java:83)
        at javafx.web/com.sun.webkit.Timer.notifyTick(Timer.java:64)
        at javafx.web/javafx.scene.web.WebEngine$PulseTimer.lambda$static$0(WebEngine.java:1196)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:424)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:423)
        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(Thread.java:844)

        Note that the exception prevents the image from being read and converted into a Data URL.

        The fix will be to copy the SwingFXUtils.fromFXImage method into a private method in javafx.web and modify it to not use sun.awt.image.IntegerComponentRaster


        The workaround is to add the swing module and also add one of the needed qualified exports as follows:

            --add-modules=javafx.swing --add-exports java.desktop/sun.awt.image=javafx.swing


          Issue Links



                psadhukhan Prasanta Sadhukhan
                kcr Kevin Rushforth
                0 Vote for this issue
                5 Start watching this issue