JDK-6764271 : Desktop.open(File) does not work reliably on Windows
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6u10
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: linux
  • CPU: x86
  • Submitted: 2008-10-27
  • Updated: 2011-04-28
Description
Run this in XP sp2:

---%<---
import java.awt.Desktop;
import java.io.File;
public class OpenInSystem {
    public static void main(String[] args) throws Exception {
        File f = File.createTempFile("something", "txt");
        System.err.println(f);
        Desktop.getDesktop().open(f);
    }
}
---%<---

I get:

---%<---
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)
C:\DOCUME~1\dev\LOCALS~1\Temp\something27450txt
Exception in thread "main" java.io.IOException: Failed to open file:/C:/DOCUME~1/dev/LOCALS~1/Temp/something27450txt. Error message: The parameter is incorrect.

        at sun.awt.windows.WDesktopPeer.ShellExecute(WDesktopPeer.java:59)
        at sun.awt.windows.WDesktopPeer.open(WDesktopPeer.java:36)
        at java.awt.Desktop.open(Desktop.java:254)
        at OpenInSystem.main(OpenInSystem.java:7)
---%<---

It is not clear what the message "The parameter is incorrect." is referring to exactly; the parameter is the path to an existing file, and the URI looks to be fine.

But if "txt" is replaced with ".txt" then Notepad is opened on the file as expected. It is not surprising that Windows has no application ready to open a file without extension, but the error message is inappropriate, and I would at least expect a regular application chooser dialog, as if you had double-clicked the file in Explorer.

Calling getCanonicalPath() does not help.