JDK-6599987 : Calling Desktop.open() on an mp3 file fails with IOException
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6,6u2
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: solaris_2.5.1,windows_xp
  • CPU: x86,sparc
  • Submitted: 2007-08-31
  • Updated: 2011-01-19
  • Resolved: 2008-07-22
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.
JDK 7
7Resolved
Related Reports
Relates :  
Relates :  
Relates :  
Description
OPERATING SYSTEM(S):
--------------------
Windows XP Professional SP2

FULL JDK VERSION(S):
-------------------
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b04)
Java HotSpot(TM) Client VM (build 1.6.0_02-b04, mixed mode)

DESCRIPTION:
------------

PROBLEM DESCRIPTION

Opening an MP3 file using Desktop.open() failed with IOException. 

Note: problem is seen only on some machines (Where winamp is not available as default mp3 player and windows media player is the only player by default available for mp3 files).

Exception details are below:

java.io.IOException: Failed to open file:/C:/hello.mp3. Error mess
age: The system cannot find the file specified.

        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 DesktopOpen.main(DesktopOpen.java:14)


TEST CASE:

import java.awt.Desktop;
import java.io.*;

class DesktopOpenTest {

    DesktopOpenTest()
    {
    }

    public static void main(String args[])
    {
        if (args.length <= 0) {
            System.out.println("usage: java DesktopOpenTest <filename>");
            System.exit(-1);
        }
        Desktop desktop = null;
        if (Desktop.isDesktopSupported())
            desktop = Desktop.getDesktop();
        else
            System.out.println("Desktop is not supported on this platform");
        try {
            desktop.open(new File(args[0]));
        } catch (IOException ioexception) {
            System.out.println("Desktop open failed with IOException");
            ioexception.printStackTrace();
        }
    }
}

Comments
EVALUATION This is not a defect. In the description example we do something like that desktop.open(new File("file:/C:/hello.mp3")); But "file:/C:/hello.mp3" is not a file name, it is URI. So we have to use java.io.File(URI)constructor here. In other words desktop.open(new File(new URI("file:/C:/hello.mp3"))); This approach works. In a JavaDoc for java.io.File(String) is written that it /** * Creates a new <code>File</code> instance by converting the given * pathname string into an abstract pathname. If the given string is * the empty string, then the result is the empty abstract pathname. .... Since "file:/C:/hello.mp3" is not a pathname string, but URI string, file implementation handles this string incorrectly. So we cannot use it in open implementation.
22-07-2008

WORK AROUND There is no known workaround as far as the conversion from File to URI is in AWT code.
29-11-2007

EVALUATION The current implementation of AWT Desktop on Windows platform converted all resources (irrespective of whether it is edit, open, browse or mail action) in URI. After installing Windows XP SP 2 looks like something was changend in the implementation of ShellExecute Win API function. From SP2 ShellExecute does not handle file URIs as the function does it before.
29-11-2007

SUGGESTED FIX ------- WDesktopPeer.java ------- *** /tmp/sccs.Tf1iKR Thu Nov 29 16:48:27 2007 --- WDesktopPeer.java Thu Nov 29 13:19:11 2007 *************** *** 51,65 **** } public void open(File file) throws IOException { ! this.ShellExecute(file.toURI(), ACTION_OPEN_VERB); } public void edit(File file) throws IOException { ! this.ShellExecute(file.toURI(), ACTION_EDIT_VERB); } public void print(File file) throws IOException { ! this.ShellExecute(file.toURI(), ACTION_PRINT_VERB); } public void mail(URI uri) throws IOException { --- 51,65 ---- } public void open(File file) throws IOException { ! this.ShellExecute(file, ACTION_OPEN_VERB); } public void edit(File file) throws IOException { ! this.ShellExecute(file, ACTION_EDIT_VERB); } public void print(File file) throws IOException { ! this.ShellExecute(file, ACTION_PRINT_VERB); } public void mail(URI uri) throws IOException { *************** *** 72,83 **** private void ShellExecute(URI uri, String verb) throws IOException { String errmsg = ShellExecute(uri.toString(), verb); ! if (errmsg != null) { ! throw new IOException("Failed to " + verb + " " + uri + ". Error message: " + errmsg); } ! } private static native String ShellExecute(String uri, String verb); --- 72,91 ---- private void ShellExecute(URI uri, String verb) throws IOException { String errmsg = ShellExecute(uri.toString(), verb); ! checkErrorMessage(errmsg, verb, uri.toString()); ! } ! ! private void ShellExecute(File file, String verb) throws IOException { ! String errmsg = ShellExecute(file.getAbsolutePath(), verb); ! checkErrorMessage(errmsg, verb, file.getAbsolutePath()); ! } ! ! private void checkErrorMessage(String errmsg, String verb, String path) throws IOException { if (errmsg != null) { ! throw new IOException("Failed to " + verb + " " + path + ". Error message: " + errmsg); } ! } private static native String ShellExecute(String uri, String verb);
29-11-2007

EVALUATION I don't have WinAmp installed on my desktop and wan't able to get exactly the same message as reported in the description (The system cannot find the file specified). However, I got several other messages (Invalid menu handle, The parameter is incorrect) while trying to get .mp3 or .wav file played. The same files are played by WMA successfully.
03-09-2007