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

java.awt.Desktop.getDesktop().open() fails on CentOS/X11 inside JavaFX app

XMLWordPrintable

    • x86
    • linux

      ADDITIONAL SYSTEM INFORMATION :
      CentOS XFCE
      Kernel: 3.10.0-1062.12.1.el7.x86_64
      Arch: x86-64
      CentOS Linux release 7.7.1908 (Core)

      Zulu: 8.44.0.13 (8u242b20) -x86-64, JavaFX enabled JDK.
      openjdk version "1.8.0_202"
      OpenJDK Runtime Environment (Zulu 8.36.0.1-CA-linux64) (build 1.8.0_202-b05)
      OpenJDK 64-Bit Server VM (Zulu 8.36.0.1-CA-linux64) (build 25.202-b05, mixed mode)

      AND

      Oracle JDK 1.8.0_241


      A DESCRIPTION OF THE PROBLEM :
      I have some code where I attempt to load a PDF file with AWT api inside of a JavaFX application.
      Please note that outside of a JavaFX context, the AWT code executes as expected.
      The bug was discovered when stepping through code that looks like this.

      @Deprecated
      private void loadDocAWT(String pdfURL) {
      try {
      File pdf = File.createTempFile("sample", ".pdf");
      //File pdf = new File ("sample.pdf");
      InputStream in = new URL(pdfURL).openStream();
      Files.copy(in, pdf, StandardCopyOption.REPLACE_EXISTING);
      java.awt.Desktop.getDesktop().open(pdf);
      } catch (IOException ioe) {
      //log
      LoggerFactory.getLogger(Demo.class).warn("An I/O Error occurred in loading PDF data.");
      ...
      }
      }

      This method is invoked in the context of event driven programming in JavaFX.
      A button object is Target of the event. In my testing, the mouse is the source of the event.
      And the type is a MouseEvent. I was, however, listening for an ActionEvent. These are JavaFX classes.

      TL;DR - A user clicks on a button, and this method is invoked as a consequence.

      Inside the subroutine, sun.awt.X11.XDesktopPeer.launch(URI uri), a call to the native method gnome_url_show(byte[] url) is made. It is there where the application becomes unresponsive.

      When testing this issue with the Oracle JDK, when it reaches the aforementioned call to the native method gnome_url_show(byte[] url), it always fails to succeed.
      When testing this issue with the Zulu 8 JDK, the method completes normally the first time, and fails subsequently.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      The issue can be reproduced with the following source code.
      https://gist.github.com/afinlay5/23b570415a99c862d01775bfb4d0536c

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It is expected that the java.awt.Desktop.getDesktop().open() completes normally and opens up the PDF file with the default handler of the file type for the OS or prompts the user to choose an application with which to load the file.
      ACTUAL -
      Please see description. With Oracle JDK, this attempt is never successful. With the Zulu JDK the subroutine completes normally the first time, but does not succeed thereafter.

      ---------- BEGIN SOURCE ----------
      The source may be found here:
      https://gist.github.com/afinlay5/23b570415a99c862d01775bfb4d0536c
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      javafx.application.HostServices.showDocument(String uri) solves the problem for us in JavaFX 11/JSE 11. It does not work for us in JSE 8 using ZuluFX, however, it does work using Oracle JDK 8. We are not, however, running Oracle JDK 8 in production.

      FREQUENCY : always


            bvaidya Balchandra Vaidya
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: