JDK-6457562 : destop.browse(URI) tries to find the uri encoded location
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2006-08-07
  • Updated: 2010-04-04
  • Resolved: 2006-08-09
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0-beta2"
Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86)
Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode, sharing)

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

A DESCRIPTION OF THE PROBLEM :
Using the desktop.browse(URI) command. It seems to have problems with the URI if the address contains spaces or other escaped characters. It replaces the escaped characters but when you attempt to open the default browser it attempts to find a file containing the escape characters rather than using the correct file path.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the supplied code

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
should open the desired web page
ACTUAL -
Tries to open the page;
C:\Output%20DOC\Default_CSH.htm%231



ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.io.IOException:
Failed to open file:/C:/Output%20DOC/Default_CSH.htm%231.
Error message: The system cannot find the path specified.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
File w = new File("C:\\Output DOC\\Default_CSH.htm#1");
URI uri = w.toURI();
desktop = Desktop.getDeskTop();

desktop.browse(uri);

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

Comments
EVALUATION I tried the test with the string "C:\\Output DOC\\Default_CSH.htm" with both IE and Mozilla as a default browser, and no problems appeared even with escaped whitespace characters. Thus, it seems that the problem is with # character. Then I noticed how URI is constructed in the test: we create a File for a given name and then call to its toURI() method. This leads to the whole string, including # character, is interpreted as a filename, that's why we get an error message. To make the test work one should construct URI the following way: new URI("http://download.java.net/jdk6/docs/api/java/awt/Button.html#getLabel()") Note, that if you open a file using file:// protocol then you can't specify what place in it should be positioned with #href. This is only possible when you use http:// protocol like in example above. So I'm closing this bug as not a defect.
09-08-2006