WindowsPathParser.normalize throws the exception on normalizing path acquired by other java internal methods.
The following demonstrates the behaviour:
java.nio.file.Path p;
p = Paths.get(new URI("file://" + MyTest.class.getResource("").getPath())); // ok
p = Paths.get(MyTest.class.getResource("").getPath()); // fails
The stacktrace:
java.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:/somepath/
at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:204)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:175)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:231)
at java.base/java.nio.file.Path.of(Path.java:148)
at java.base/java.nio.file.Paths.get(Paths.java:69)
at MyTest.testWindowsPath
At the same time the following works fine:
FileInputStream fileInputStream = new FileInputStream(MyTest.class.getResource("").getPath() + "/MyTest.class");
The following demonstrates the behaviour:
java.nio.file.Path p;
p = Paths.get(new URI("file://" + MyTest.class.getResource("").getPath())); // ok
p = Paths.get(MyTest.class.getResource("").getPath()); // fails
The stacktrace:
java.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:/somepath/
at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:204)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:175)
at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:231)
at java.base/java.nio.file.Path.of(Path.java:148)
at java.base/java.nio.file.Paths.get(Paths.java:69)
at MyTest.testWindowsPath
At the same time the following works fine:
FileInputStream fileInputStream = new FileInputStream(MyTest.class.getResource("").getPath() + "/MyTest.class");
- relates to
-
JDK-8321591 (fs) Improve String -> Path conversion performance (win)
-
- Resolved
-