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

        Attachments

          Issue Links

            Activity

              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: