Details
-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8, 11, 17, 18, 19, 20
-
x86_64
-
windows_10
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 10 Pro 21H2, x64
openjdk version "17.0.4"
A DESCRIPTION OF THE PROBLEM :
On Windows 10 and with Java 17.0.4 the java.nio.file.Path class wont recognize a path which contains just the drive name, e.g. "C:" as an absolute path if the current working directory is also somewhere on the same drive.
In addition, and worse in my opinion, the toAbsolutePath method will return just the current working directory for this path object.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
To reproduce the problem just execute this code snippet on an Windows 10 machine, with the current working directory in some subdirectory of the system drive "C:".
Path workingPath = Paths.get("").toAbsolutePath();
System.out.println("workingPath: " + workingPath);
Path testPath = Paths.get("C:");
System.out.println("testPath: " + testPath);
System.out.println("testPath.isAbsolute: " + testPath.isAbsolute());
System.out.println("testPath.toAbsolutePath: " + testPath.toAbsolutePath());
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect "C:" to be recognized as absolute path, just as "C:\" is.
I would also expect the result of the toAbsoultePath method to be "C:\" and not to be the current working directory.
ACTUAL -
The output of this code snippet if my current working directory is "C:\test\path":
workingPath: C:\test\path
testPath: C:
testPath.isAbsolute: false
testPath.toAbsolutePath: C:\test\path\
---------- BEGIN SOURCE ----------
import java.nio.file.Path;
import java.nio.file.Paths;
public class Test
{
public static void main(String[] args)
{
Path workingPath = Paths.get("").toAbsolutePath();
System.out.println("workingPath: " + workingPath);
Path testPath = Paths.get("E:");
System.out.println("testPath: " + testPath);
System.out.println("testPath.isAbsolute: " + testPath.isAbsolute());
System.out.println("testPath.toAbsolutePath: " + testPath.toAbsolutePath());
}
}
---------- END SOURCE ----------
FREQUENCY : always
Windows 10 Pro 21H2, x64
openjdk version "17.0.4"
A DESCRIPTION OF THE PROBLEM :
On Windows 10 and with Java 17.0.4 the java.nio.file.Path class wont recognize a path which contains just the drive name, e.g. "C:" as an absolute path if the current working directory is also somewhere on the same drive.
In addition, and worse in my opinion, the toAbsolutePath method will return just the current working directory for this path object.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
To reproduce the problem just execute this code snippet on an Windows 10 machine, with the current working directory in some subdirectory of the system drive "C:".
Path workingPath = Paths.get("").toAbsolutePath();
System.out.println("workingPath: " + workingPath);
Path testPath = Paths.get("C:");
System.out.println("testPath: " + testPath);
System.out.println("testPath.isAbsolute: " + testPath.isAbsolute());
System.out.println("testPath.toAbsolutePath: " + testPath.toAbsolutePath());
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect "C:" to be recognized as absolute path, just as "C:\" is.
I would also expect the result of the toAbsoultePath method to be "C:\" and not to be the current working directory.
ACTUAL -
The output of this code snippet if my current working directory is "C:\test\path":
workingPath: C:\test\path
testPath: C:
testPath.isAbsolute: false
testPath.toAbsolutePath: C:\test\path\
---------- BEGIN SOURCE ----------
import java.nio.file.Path;
import java.nio.file.Paths;
public class Test
{
public static void main(String[] args)
{
Path workingPath = Paths.get("").toAbsolutePath();
System.out.println("workingPath: " + workingPath);
Path testPath = Paths.get("E:");
System.out.println("testPath: " + testPath);
System.out.println("testPath.isAbsolute: " + testPath.isAbsolute());
System.out.println("testPath.toAbsolutePath: " + testPath.toAbsolutePath());
}
}
---------- END SOURCE ----------
FREQUENCY : always