JDK-8064934 : Incorrect Exception message from java.awt.Desktop.open()
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7u40,7u71,8,8u40,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • Submitted: 2014-11-14
  • Updated: 2021-01-22
  • Resolved: 2015-02-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
7u85Fixed 8u60Fixed 9 b52Fixed
Related Reports
Relates :  
If Desktop.open() fails because the target file has no associated, an 
IOException is thrown with the following error message:
  "A device attached to the system is not functioning."

This is not the correct error message. It should be:
  "There is no application associated with the given file name extension."

Prior to 7u40, a different (but still incorrect) Exception message was shown:
  "Access is denied."

The test leaves the Windows dialog ���How do you want to open this file?��� open on newer Windows versions. See https://bugs.openjdk.java.net/browse/JDK-8204537?focusedCommentId=14395514&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-14395514

In Java_sun_awt_windows_WDesktopPeer_ShellExecute() we pass to FormatMessage() the error code returned by ShellExecute() function. This is not correct, since error codes returned by ShellExecute() are not covered by System Error Codes. So we have to pass to FormatMessage() the error code returned by GetLastError() function instead of code returned by ShellExecute().

Testcase & Reproduction Instructions ------------------------------------ 1. Create "test.foo" file. Its extension should not be linked to a default application. 2. Compile and launch the testcase. > java DesktopTest test.foo Observe the incorrect Exception message as per the problem description section above: java.io.IOException: Failed to open test.foo. Error message: A device attached to the system is not functioning. at sun.awt.windows.WDesktopPeer.ShellExecute(WDesktopPeer.java:82) at sun.awt.windows.WDesktopPeer.open(WDesktopPeer.java:56) at java.awt.Desktop.open(Desktop.java:272) at DesktopTest.main(DesktopTest.java:19) DesktopTest.java ---------------- import java.awt.*; import java.io.*; public class DesktopTest { public static void main(String[] args) { if (!Desktop.isDesktopSupported()) { System.err.println("Desktop is not supported"); return; } if (args.length != 1) { System.err.println("Usage: java DesktopTest filename"); return; } Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { System.out.println("Open is supported !"); try { File file = new File(args[0]); desktop.open(file); } catch (IOException e) { e.printStackTrace(); } } else { System.out.println("Open is not supported"); } } }