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

[WebView] IllegalStateException when invoking print API with html form controls

    XMLWordPrintable

    Details

    • Subcomponent:
      web
    • Introduced In Version:
    • CPU:
      x86_64
    • OS:
      generic

      Backports

        Description

        ADDITIONAL SYSTEM INFORMATION :
        OS: Ubuntu 14.04 / 18.04 / Windows 10 Pro 1803
        Java: Java 8 Update 172/181

        A DESCRIPTION OF THE PROBLEM :
        When I print WebView by PrinterJob.printPage(Node), IllegalStateException is thrown. the page is printed omitting checkboxes. Printing by WebEngine.print(PrinterJob) results in the same.
        A similar problem is reported in
        https://stackoverflow.com/questions/50476171/illegalstateexeption-when-using-javafx-webengine-print-function

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Load a HTML page by WebView in JavaFX. The HTML contains checkboxes.
        Print the WebView by PrinterJob.printPage(Node).

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The WebView is printed as shown on the screen.
        ACTUAL -
        The WebView is printed, but checkboxes is not printed. And IllegalStateException is thrown as follows:

        Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: the method should not be called in this context
        at com.sun.javafx.webkit.theme.RenderThemeImpl.ensureNotDefault(RenderThemeImpl.java:250)
        at com.sun.javafx.webkit.theme.RenderThemeImpl.createWidget(RenderThemeImpl.java:263)
        at com.sun.webkit.WebPage.twkUpdateContent(Native Method)
        at com.sun.webkit.WebPage.lambda$print$40(WebPage.java:666)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.gtk.GtkApplication.enterNestedEventLoopImpl(Native Method)
        at com.sun.glass.ui.gtk.GtkApplication._enterNestedEventLoop(GtkApplication.java:211)
        at com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:511)
        at com.sun.glass.ui.EventLoop.enter(EventLoop.java:107)
        at com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:590)
        at com.sun.prism.j2d.print.J2DPrinterJob$J2DPageable.implPrintPage(J2DPrinterJob.java:1146)
        at com.sun.prism.j2d.print.J2DPrinterJob$J2DPageable.access$500(J2DPrinterJob.java:972)
        at com.sun.prism.j2d.print.J2DPrinterJob.print(J2DPrinterJob.java:797)
        at javafx.print.PrinterJob.printPage(PrinterJob.java:398)
        at javafx.print.PrinterJob.printPage(PrinterJob.java:414)
        at bugreport.Main.print(Main.java:67)
        at bugreport.Main.lambda$2(Main.java:45)
        at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
        at com.sun.glass.ui.gtk.GtkApplication.lambda$null$48(GtkApplication.java:139)
        at java.lang.Thread.run(Thread.java:748)
        Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: the method should not be called in this context
        at com.sun.javafx.webkit.theme.RenderThemeImpl.ensureNotDefault(RenderThemeImpl.java:250)
        at com.sun.javafx.webkit.theme.RenderThemeImpl.createWidget(RenderThemeImpl.java:263)
        at com.sun.webkit.WebPage.twkUpdateContent(Native Method)
        at com.sun.webkit.WebPage.lambda$print$40(WebPage.java:666)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.gtk.GtkApplication.enterNestedEventLoopImpl(Native Method)
        at com.sun.glass.ui.gtk.GtkApplication._enterNestedEventLoop(GtkApplication.java:211)
        at com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:511)
        at com.sun.glass.ui.EventLoop.enter(EventLoop.java:107)
        at com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:590)
        at com.sun.prism.j2d.print.J2DPrinterJob$J2DPageable.implPrintPage(J2DPrinterJob.java:1146)
        at com.sun.prism.j2d.print.J2DPrinterJob$J2DPageable.access$500(J2DPrinterJob.java:972)
        at com.sun.prism.j2d.print.J2DPrinterJob.print(J2DPrinterJob.java:797)
        at javafx.print.PrinterJob.printPage(PrinterJob.java:398)
        at javafx.print.PrinterJob.printPage(PrinterJob.java:414)
        at bugreport.Main.print(Main.java:67)
        at bugreport.Main.lambda$2(Main.java:45)
        at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
        at com.sun.glass.ui.gtk.GtkApplication.lambda$null$48(GtkApplication.java:139)
        at java.lang.Thread.run(Thread.java:748)


        ---------- BEGIN SOURCE ----------
        ------Main.java----------------
        package bugreport;

        import java.util.concurrent.CountDownLatch;

        import javafx.application.Application;
        import javafx.application.Platform;
        import javafx.beans.value.ChangeListener;
        import javafx.concurrent.Worker.State;
        import javafx.print.Printer;
        import javafx.print.PrinterJob;
        import javafx.stage.Stage;
        import javafx.scene.Scene;
        import javafx.scene.web.WebEngine;
        import javafx.scene.web.WebView;


        public class Main extends Application {
        @Override
        public void start(Stage primaryStage) {
        try {
        WebView root = new WebView();
        WebEngine engine = root.getEngine();
        engine.load(getClass().getResource("BugReport.html").toString());

        CountDownLatch latch = new CountDownLatch(1);
        ChangeListener<State> loadFinish = (observable, oldValue, newValue) -> {
        if (newValue == State.SUCCEEDED) {
        latch.countDown();
        }
        };
        engine.getLoadWorker().stateProperty().addListener(loadFinish);

        Scene scene = new Scene(root,400,400);
        primaryStage.setScene(scene);
        primaryStage.show();

        new Thread(() -> {
        // wait the html loaded.
        try {
        latch.await();
        } catch (InterruptedException e) {
        }
        Platform.runLater(() -> {
        print(root);
        /*
        PrinterJob job = PrinterJob.createPrinterJob(Printer.getDefaultPrinter());
        engine.print(job);
        job.endJob();
        */
        });
        }).start();

        } catch(Exception e) {
        e.printStackTrace();
        }
        }

        public static void main(String[] args) {
        launch(args);
        }

        private static void print(WebView node) {
        Printer printer = Printer.getDefaultPrinter();
        if (printer != null) {
        PrinterJob job = PrinterJob.createPrinterJob(printer);
        try {
        job.printPage(node);
        } finally {
        job.endJob();
        }
        }
        }
        }
        --------End of Main.java-----------------------------------------------------------
        -----------BugReport.html----------------------------------------
        <!DOCTYPE html>
        <html>
          <head>
            <meta http-equiv="content-type" content="text/html; charset=UTF-8">
            <title>BugReport</title>
          </head>
          <body><input name="bugreport" type="checkbox">
            <p>This sentence is printed.<br>
            </p>
          </body>
        </html>
        ---------End of BugReport.html--------------------
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        In my case, no exception is thrown when checkboxes are removed from the HTML.
        But the checkboxes are not printed, of course.

        FREQUENCY : always


          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  arajkumar Arunprasad Rajkumar
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: