JDK-8096706 : Frozen jvm when calling desktop.open(FILE) on Ubuntu
  • Type: Bug
  • Component: javafx
  • Sub-Component: swing
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2014-03-23
  • Updated: 2018-01-15
  • Resolved: 2014-03-24
Related Reports
Duplicate :  
Duplicate :  
Description
My requirement is to have a button that opens a given pdf file or directory available on the filesystem using the platform default application (i,e, Explorer/Nautilus/etc for the directories and AcrobatReader/Evince/etc for the pdf file). 
I'm not sure what's the JavaFX best practice to fulfil this requirement but my understanding is that the following code, even though an awt api, should work:
 if (Desktop.isDesktopSupported()) {
      Desktop.getDesktop().open(FILE);
 }
There are 2 issues here:
1. Is this supposed to work when called from the FX thread? According to RT-31468 it shouldn't, but then it's used in the official documentation http://docs.oracle.com/javafx/2/ui_controls/file-chooser.htm suggesting it should work 
2. If it is supposed to work then RT-31468 is a valid bug, tested on Ubuntu 12.10 and 13.10, the jvm freezes. Everything works on Windows 7.

A workaround suggested on the support forum is to use HostServices.showDocument which again works perfectly on Windows but on Ubuntu opens every file or directory using the default browser (Firefox in my case)

To summarize I think what should be addressed is:
1. Have Desktop.open and HostServices.showDocument to work consistently across multiple operating systems.
2. Have some official documentation showing the JavaFX way to fulfil the "open a file/directory using the default viewer/application" requirement which I think is quite common for a desktop application.
Comments
21-08-2014

I mean this JIRA instance at https://javafx-jira.kenai.com/. You can find a Create Issue link at the upper-right corner on any page here. "Tweak" is the issue type that you need to file, and "AppModel" is the Component against which the issue should be filed. All this information will be requested when you're creating a new issue.
21-08-2014

kk, thanks for your care and explanation. I still think, your workaround posted above (wrapping the Desktop-calls in "EventQueue.invokeLater") is no perfect solution, so I'm still a bit unlucky with the "Status quo". But I agree to your arguments on https://bugs.openjdk.java.net/browse/JDK-8055517. In point 4 you mentioned, extending the HostServices class. I think this would be an elegant alternative to your workaround. But I did not understand know how to create an issue the required way. What do you mean with "file an Tweak issue in JIRA against the AppModel component and request the enhancement"? Which JIRA do you mean, what is the "AppModel"?
21-08-2014

FYI: https://bugs.openjdk.java.net/browse/JDK-8055517 was just closed as Not an Issue.
20-08-2014

Hi Timo, I'm not sure I fully understand what you're requesting. Could you please rephrase it? From what I understood, the code itself looks OK. Just remember that any AWT APIs must only be called from the AWT's EDT thread. If you have any suggestions regarding the JDK API, please file an RFE against JDK at http://bugs.sun.com/
19-08-2014

Hey Anthony Petrov. Thanks for your explanation, it works fine in my application now. But I think, it's still a bit confusing. From what you read (without knowing your explanations) this seems to be nice code: if (desktop.isSupported(Action.BROWSE)) { desktop.browse(URI.create(url)); } I think it would be great to change the Method Desktop.isSupported accordingly
18-08-2014

I've submitted RT-36349 to track the bug in the JavaFX documentation.
24-03-2014

1. RT-31468 is not an issue because calling AWT APIs on the FX App Thread is a violation of threading policies for both AWT and FX. 2. The documentation that you're referring to predates the RT-31468 bug, and as such the threading restrictions have not been documented properly. I'll submit an issue against the tutorial so that it gets fixed eventually. Sorry for any inconvenience. 3. In order to use the API, you have to call java.awt.EventQueue.invokeLater() and call methods of the Desktop class from a runnable passed to the invokeLater(): void fxEventHandler() { EQ.invokeLater(() -> { Desktop.open(...); }); } 4. As far as I can tell, the HostServices.showDocument() method works according to its specification. If you wish to have it extended, or introduce a new method to the HostServices class, please file an Tweak issue in JIRA against the AppModel component and request the enhancement.
24-03-2014