-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8, 11, 15, 17
A DESCRIPTION OF THE PROBLEM :
The implementation in constructor of File(URI) throws an IllegalArgumentException("URI has an authority component") when using a pathname in UNC notation (e.g. "//nas/root"). The bug is, that the URI authority for schema "file:" is part of the path.
Using File("//nas/root") works as expected.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
File file = new File(new URL("//nas/root").toURI());
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
file is valid
ACTUAL -
IllegalArgumentException("URI has an authority component")
---------- BEGIN SOURCE ----------
File file = new File(new URL("//nas/root").toURI());
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
in File(URI):
// Check our many preconditions
if (!uri.isAbsolute())
throw new IllegalArgumentException("URI is not absolute");
if (uri.isOpaque())
throw new IllegalArgumentException("URI is not hierarchical");
String scheme = uri.getScheme();
if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
throw new IllegalArgumentException("URI scheme is not \"file\"");
/* bug: omit this statement
if (uri.getRawAuthority() != null)
throw new IllegalArgumentException("URI has an authority component");
*/
if (uri.getRawFragment() != null)
throw new IllegalArgumentException("URI has a fragment component");
if (uri.getRawQuery() != null)
throw new IllegalArgumentException("URI has a query component");
// and here the correction
String uncPath;
if (uri.getRawAuthority() == null) {
// the old behaviour
uncPath = uri.getPath();
if (uncPath.isEmpty())
throw new IllegalArgumentException("URI path component is empty");
}else {
// the corrected behaviour with an UNC path
// remember: URI is a file:
uncPath = "//" + uri.getRawAuthority() + uri.getPath();
}
// contiunue the code...
FREQUENCY : always
The implementation in constructor of File(URI) throws an IllegalArgumentException("URI has an authority component") when using a pathname in UNC notation (e.g. "//nas/root"). The bug is, that the URI authority for schema "file:" is part of the path.
Using File("//nas/root") works as expected.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
File file = new File(new URL("//nas/root").toURI());
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
file is valid
ACTUAL -
IllegalArgumentException("URI has an authority component")
---------- BEGIN SOURCE ----------
File file = new File(new URL("//nas/root").toURI());
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
in File(URI):
// Check our many preconditions
if (!uri.isAbsolute())
throw new IllegalArgumentException("URI is not absolute");
if (uri.isOpaque())
throw new IllegalArgumentException("URI is not hierarchical");
String scheme = uri.getScheme();
if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
throw new IllegalArgumentException("URI scheme is not \"file\"");
/* bug: omit this statement
if (uri.getRawAuthority() != null)
throw new IllegalArgumentException("URI has an authority component");
*/
if (uri.getRawFragment() != null)
throw new IllegalArgumentException("URI has a fragment component");
if (uri.getRawQuery() != null)
throw new IllegalArgumentException("URI has a query component");
// and here the correction
String uncPath;
if (uri.getRawAuthority() == null) {
// the old behaviour
uncPath = uri.getPath();
if (uncPath.isEmpty())
throw new IllegalArgumentException("URI path component is empty");
}else {
// the corrected behaviour with an UNC path
// remember: URI is a file:
uncPath = "//" + uri.getRawAuthority() + uri.getPath();
}
// contiunue the code...
FREQUENCY : always