JDK-6360233 : Deprecated toURL method does not handle UNC path
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 5.0u6
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows
  • CPU: x86
  • Submitted: 2005-12-07
  • Updated: 2017-05-19
  • Resolved: 2006-04-27
Related Reports
Relates :  
Relates :  
Relates :  
Description
Here is a scenario which shows the problem:

File f = new File("\\\\machine\\officebean.dll");
URL url = f.toURL();
String s = url.toString();          
URI u = new URI(s);
File f2 = new File(u);

During instantiation of f2 an IllegalArgumentException is thrown. The message is "URI has an authority component." The problem seems to be URL.toString which returns:
"file://machine/officebean.dll"
It would work if toString returned:
"file:////machine/officebean.dll"

Comments
EVALUATION -- The toURL() method creates the URL using java.net.URL's component-wise ctor with the result that the server name goes into the authority component. This is long standing legacy behaviour that is too risky to change now. As of J2SE 5.0 this method has been deprecated. The toURI() method does the right thing.
06-04-2006

WORK AROUND Use the toURI method instead.
06-04-2006

EVALUATION See comment.
11-01-2006