Commit 2c64dead by Jeroen Frijters Committed by Andreas Tobler

File.java File (String,String): Fixed handling of empty path.

2004-08-30  Jeroen Frijters  <jeroen@frijters.net>

	* java/io/File.java File(String,String): Fixed handling of empty
	path.

From-SVN: r86774
parent 89b8abbf
2004-08-30 Jeroen Frijters <jeroen@frijters.net>
* java/io/File.java File(String,String): Fixed handling of empty
path.
2004-08-30 Casey Marshall <csm@gnu.org> 2004-08-30 Casey Marshall <csm@gnu.org>
Author e-mail updated for all files. Author e-mail updated for all files.
......
...@@ -361,7 +361,9 @@ public class File implements Serializable, Comparable ...@@ -361,7 +361,9 @@ public class File implements Serializable, Comparable
{ {
if (name == null) if (name == null)
throw new NullPointerException(); throw new NullPointerException();
if (dirPath != null && dirPath.length() > 0) if (dirPath != null)
{
if (dirPath.length() > 0)
{ {
// Try to be smart about the number of separator characters. // Try to be smart about the number of separator characters.
if (dirPath.charAt(dirPath.length() - 1) == separatorChar if (dirPath.charAt(dirPath.length() - 1) == separatorChar
...@@ -371,6 +373,27 @@ public class File implements Serializable, Comparable ...@@ -371,6 +373,27 @@ public class File implements Serializable, Comparable
path = normalizePath(dirPath + separatorChar + name); path = normalizePath(dirPath + separatorChar + name);
} }
else else
{
// If dirPath is empty, use a system dependant
// default prefix.
// Note that the leading separators in name have
// to be chopped off, to prevent them forming
// a UNC prefix on Windows.
if (separatorChar == '\\' /* TODO use ON_WINDOWS */)
{
int skip = 0;
while(name.length() > skip
&& (name.charAt(skip) == separatorChar
|| name.charAt(skip) == '/'))
{
skip++;
}
name = name.substring(skip);
}
path = normalizePath(separatorChar + name);
}
}
else
path = normalizePath(name); path = normalizePath(name);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment