JDK-6550588 : java.awt.Desktop cannot open file with Windows UNC filename
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-04-26
  • Updated: 2013-09-12
  • Resolved: 2013-03-29
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 6 JDK 7 JDK 8
6u51Fixed 7u21Fixed 8Fixed
Description
FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [version 5.1.2600]


A DESCRIPTION OF THE PROBLEM :
Hi,

The java.awt.Desktop class does not allow to open a network file with blank character into the path. For example, it fails to open "//serverName/drive/Temp/my folder/a simple file.xxx", where xxx may be any extension : txt, pdf...

For information, it works if the path contains the drive letter "N:/Temp/my folder/a simple file.txt", or if the path does not contain any blank like "//serverName/drive/Temp/my_folder/a_simple_file.txt".


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should open the file with the application used for its extension, like Notepad for txt file.
ACTUAL -
IOException

ERROR MESSAGES/STACK TRACES THAT OCCUR :
The ouput is:

java.io.IOException: Failed to open file:////serverName/drive/Temp/my%20folder/a%20simple%20file.txt. Error message: Le chemin d'acc��s sp��cifi�� est introuvable.
        at sun.awt.windows.WDesktopPeer.ShellExecute(Unknown Source)
        at sun.awt.windows.WDesktopPeer.open(Unknown Source)
        at java.awt.Desktop.open(Unknown Source)
        at Swing.myDesktop.main(jvDesktop.java:26)



REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package Swing;

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

public class myDesktop
{
	public static void main(String[] args)
	{
	    try
	    {
			Desktop myDesktop = null;
			if (Desktop.isDesktopSupported())
				myDesktop = Desktop.getDesktop();

			if (myDesktop != null)
			{
				// -> Works
				//File myFile = new File("//sma-nasft04-1/servev/Temp/my_folder/a_simple_file.txt");
				//File myFile = new File("N:/Temp/my folder/a simple file.txt");

				// -> Does not work
				File myFile = new File("//sma-nasft04-1/servev/Temp/my folder/a simple file.txt");

				if (myFile.exists())
					myDesktop.open(myFile);
				else
					System.out.println("This file is not a valid one");
			}
		}
	    catch (IOException e)
	    {
			e.printStackTrace();
	    }
	}
	
}

---------- END SOURCE ----------

Comments
Verified using following code: import java.awt.*; import java.io.*; public class UncTest { public static void main(String[] args) { try { Desktop myDesktop = null; if (Desktop.isDesktopSupported()) { myDesktop = Desktop.getDesktop(); } if (myDesktop != null) { // -> Works //File myFile = new File("//stt-13.russia.sun.com/export/home0/tmp/fox/unc_test_file.txt"); //File myFile = new File("K://tmp/fox/unc test file.txt"); // -> Does not work File myFile = new File("//stt-13.russia.sun.com/export/home0/tmp/fox/unc test file.txt"); if (myFile.exists()) { myDesktop.open(myFile); } else { System.out.println("This file is not a valid one"); } } } catch (IOException e) { e.printStackTrace(); } } }
09-08-2013

Because documentation from MSDN which describes "ShellExecute" Windows Shell function does not have any mention of URI in the context of "lpFile" argument, and "java.io.File.getAbsolutePath" method returns a full absolute file path for both UNC pathnames and local file paths, which is perfectly accepted by "ShellExecute" function, I think that conversion of "java.io.File" objects into "java.net.URI" objects before passing them to "ShellExecute" function for "open", "edit" and "print" verbs is extra in Windows specific part of "java.awt.Desktop" class. Transferring of a string constructed from "java.io.File" object instead of a string built from "java.net.URI" object to "ShellExecute" function successfully resolves this bug in the local test environment.
11-03-2013

During analysis of this bug the following facts were defined: 1. URI strings constructed from Windows UNC pathnames like former mentioned "\\host\path\to\f i l e.txt" can still be handled by "ShellExecute()" Windows Shell function, if the URI string is not encoded. Presence of space characters in the URI string does not make the function fail, for example "file:////host/path/to/f i l e.txt" can be successfully processed by "ShellExecute()" function. 2. Windows API is designed to handle URI strings with "file" protocol scheme correctly, when the strings have certain number of '/' characters after the scheme name: - 2 slashes for URI converted from a Windows UNC pathname. For example, "\\host\path\to\f i l e.txt" corresponds to the URI "file://host/path/to/f%20i%20l%20e.txt". - 3 slashes for URI converted from a local Windows file path. For example, "C:\Temp Dir\f i l e.txt" corresponds to the URI "file:///C:/Temp%20Dir/f%20i%20l%20e.txt". This fact is described in the article at the following URL (http://blogs.msdn.com/b/ie/archive/2006/12/06/file-uris-in-windows.aspx). 3. Current implementation of the class "java.io.File" converts abstract file names to URI in the following way: - "C:\Temp\File.txt" -> "file:/C:/Temp/File.txt". - "\\host\SharedFolder\Temp\File.txt" -> "file:////host/SharedFolder/Temp/File.txt". Since "java.io.File" is cross-platform and stable, perhaps, additional modification of the URI string to the format expected by Windows API can be implemented in Windows specific part of "java.awt.Desktop" class.
01-03-2013

The bug is reproducible with all JDK builds which are within the following ranges: 1. JDK 6 b49 (where "java.awt.Desktop" class was introduced) - JDK 6u41 b31 (current latest JDK 6 build). 2. JDK 7 b01 - JDK 7u15 b33 (current latest JDK 7 build). 3. JDK 8 b01 - JDK 8 b78 (current latest JDK 8 build).
25-02-2013

Reopening the bug, because Microsoft company's support service refused to resolve it in their code explaining that this behavior is a design feature which should not be changed.
25-02-2013

EVALUATION File names like "\\host\path\to\f i l e.txt" are converted to the following URI: "file:////host/path/to/f%20i%20l%20e.txt" and then passed to the native ShellExecute() Win32 function. However, ShellExecute doesn't handle the strings like that, I don't know why.
27-04-2007