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

Issue opening a pdf document in webview of JavaFX FXML App

    Details

    • Subcomponent:
      web
    • CPU:
      x86
    • OS:
      other

      Description

      FULL PRODUCT VERSION :
      > java -version
      java version "1.8.0_131"
      Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

      FULL OS VERSION :
      Windows 10 Pro. version 1703, build 15063.296

      A DESCRIPTION OF THE PROBLEM :
      I was attempting to find out an issue with opening a pdf document in a browser via a JavaFX test application.
      I was stepping through the process following the breakpoint. I had stepped into the JSObject.java file when the access violation happened.

      THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Did not try

      THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Did not try

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Running the code below, clicking on the button then stepping through the from the brakepoint repeats the error.

      running the application in non-debug mode produces an exception error list.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      I had no specific expected results as I have not implemented (or attempted) a PDF reader via JavaFX.
      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      "C:\Program Files\Java\jdk1.8.0_131\bin\java" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:52164,suspend=y,server=n -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_131\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar;E:\Dropbox\IntelliJDefLocatProjects\PdfTest\out\production\PdfTest;C:\Users\nico\Downloads\commons-io-2.5.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\lib\idea_rt.jar" sample.Main
      Connected to the target VM, address: '127.0.0.1:52164', transport: 'socket'
      #
      # A fatal error has been detected by the Java Runtime Environment:
      #
      # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000733cca02, pid=10416, tid=0x00000000000008e8
      #
      # JRE version: Java(TM) SE Runtime Environment (8.0_131-b11) (build 1.8.0_131-b11)
      # Java VM: Java HotSpot(TM) 64-Bit Server VM (25.131-b11 mixed mode windows-amd64 compressed oops)
      # Problematic frame:
      # C [jfxwebkit.dll+0xcaca02]
      #
      # Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
      #
      # An error report file with more information is saved as:
      # E:\Dropbox\IntelliJDefLocatProjects\PdfTest\hs_err_pid10416.log
      #
      # If you would like to submit a bug report, please visit:
      # http://bugreport.java.com/bugreport/crash.jsp
      # The crash happened outside the Java Virtual Machine in native code.
      # See problematic frame for where to report the bug.
      #
      Disconnected from the target VM, address: '127.0.0.1:52164', transport: 'socket'

      Process finished with exit code 1


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package sample;

      import javafx.application.Platform;
      import javafx.fxml.FXML;
      import javafx.fxml.Initializable;
      import javafx.scene.control.Button;
      import javafx.scene.web.WebEngine;
      import javafx.scene.web.WebView;
      import org.apache.commons.io.FileUtils;
      import sun.misc.IOUtils;

      import java.io.File;
      import java.io.IOException;
      import java.io.InputStream;
      import java.net.URL;
      import java.util.Base64;
      import java.util.ResourceBundle;

      import org.apache.commons.io.*;

      import java.io.BufferedWriter;
      import java.io.File;
      import java.io.FileWriter;
      import java.io.IOException;
      import java.net.URL;

      public class Controller implements Initializable {

          @FXML
          Button btnTest;

          @Override
          public void initialize(URL location, ResourceBundle resources) {


          }

          @FXML
          private void openPdf() {
              WebView webView = new WebView();
              WebEngine engine = webView.getEngine();
      //Change the path according to yours.
              String url = this.getClass().getResource("resources/web/viewer.html").toExternalForm();
      //We add our stylesheet.
              engine.setUserStyleSheetLocation(getClass().getResource("resources/web/web.css").toExternalForm());
              engine.setJavaScriptEnabled(true);
              engine.load(url);

              InputStream stream = null;
              try {

                  // readFileToByteArray() comes from commons-io library
                  byte[] data = FileUtils.readFileToByteArray(new File("src/sample/resources/web/instructions.pdf"));


      // stream = myUrl.openStream();
                  //I use IOUtils from org.​apache.​commons.​io
      // byte[] data = IOUtils.toByteArray(stream);
                  //Base64 from java.util
                  String base64 = Base64.getEncoder().encodeToString(data);
                  boolean bool = Platform.isFxApplicationThread();
                  if (bool) {
                      //This must be ran on FXApplicationThread - previous bool confirms it
                      webView.getEngine().executeScript("openFileFromBase64('" + base64 + "')");
                  }else{
                      System.out.println("NOT --FX-- APPLICATION THREAD");
                  }
              } catch (Exception ex) {
                  ex.printStackTrace();
              } finally {
                  if (stream != null) {
                      try {
                          stream.close();
                      } catch (IOException ex) {
                          ex.printStackTrace();
                      }
                  }
              }
          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      none found

        Issue Links

          Activity

          Hide
          pmangal Priyanka Mangal added a comment -
          Received reproducible test case from submitter. PFA PdfTest.zip
          Reopening the bug.
          Show
          pmangal Priyanka Mangal added a comment - Received reproducible test case from submitter. PFA PdfTest.zip Reopening the bug.
          Hide
          pmangal Priyanka Mangal added a comment - - edited
          When running the attached test case (PdfTest.zip) , got below exception using 8u121 and 8u131, 8u152:
                    "netscape.javascript.JSException: TypeError: undefined is not a function"
          Could not test on JDK 9 as many packages used in test case doesn't exist in JDK 9.
          Show
          pmangal Priyanka Mangal added a comment - - edited When running the attached test case (PdfTest.zip) , got below exception using 8u121 and 8u131, 8u152:           "netscape.javascript.JSException: TypeError: undefined is not a function" Could not test on JDK 9 as many packages used in test case doesn't exist in JDK 9.
          Hide
          ghb Guru Hb added a comment -
          Exception ( "netscape.javascript.JSException: TypeError: undefined is not a function" ) is due to calling a javascript function too early (before the main page / resource is loaded by WebEngine) and its expected.
          In general, WebEngine.ExecuteScript should be called after WebEngine state is SUCCEEDED (i.e Main page and its sub resources are loaded).
          With Minor modification :
          Controller::openPdf() {
              ...
              engine.load(url);
              engine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
              if (newValue == Worker.State.SUCCEEDED) {
                  // Convert PDF file to String
                  // engine.executeScript("openFileFromBase64('" + base64 + "')");
                  }});
              ...
          }

          w.r.t PDFTest.zip (With and without above modification) i couldn't reproduce the crash.

          Will be closing this as incomplete, Please do open Re-open if the crash is still seen with above modification.
          Show
          ghb Guru Hb added a comment - Exception ( "netscape.javascript.JSException: TypeError: undefined is not a function" ) is due to calling a javascript function too early (before the main page / resource is loaded by WebEngine) and its expected. In general, WebEngine.ExecuteScript should be called after WebEngine state is SUCCEEDED (i.e Main page and its sub resources are loaded). With Minor modification : Controller::openPdf() {     ...     engine.load(url);     engine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {     if (newValue == Worker.State.SUCCEEDED) {         // Convert PDF file to String         // engine.executeScript("openFileFromBase64('" + base64 + "')");         }});     ... } w.r.t PDFTest.zip (With and without above modification) i couldn't reproduce the crash. Will be closing this as incomplete, Please do open Re-open if the crash is still seen with above modification.
          Hide
          pmangal Priyanka Mangal added a comment - - edited
          When verified test case using above modification, webview is loading the pdf document successfully using 8u121.
          For 8u131 and above java versions, webview fails to render pdf but didn't get the crash. For this, fix is required as provided in JDK-8180825.
          So closing this issue as "Not an issue"

          If this issue is seen with crash, please open a new report with all necessary information. This report ID can be referenced.
          Show
          pmangal Priyanka Mangal added a comment - - edited When verified test case using above modification, webview is loading the pdf document successfully using 8u121. For 8u131 and above java versions, webview fails to render pdf but didn't get the crash. For this, fix is required as provided in JDK-8180825 . So closing this issue as "Not an issue" If this issue is seen with crash, please open a new report with all necessary information. This report ID can be referenced.

            People

            • Assignee:
              ghb Guru Hb
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: