FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows 7 Enterprise SP1 (build 7601)
A DESCRIPTION OF THE PROBLEM :
Paths.get is not handling windows paths returned by for example: ...getResource("/resource.txt").getPath();
In that case call for Paths.get will throw exception:
java.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:/...
On Windows systems this call:
...getResource("/resource.txt").getPath();
returns path beginning with "/C:/..".
Such path representation is fully accepted by, for example File class but Paths.get is throwing exception.
Removing first character "/" is helping but in such case we will get error on *nix systems as we remove root.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
On windows system get any resource path using getResource().getPath() and try to pass it to Paths.get method.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Get correct absolute path to resource.
ACTUAL -
java.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:/...
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
URL sample = ReaderTest.class.getResource("/sample.csv");
String path = Paths.get(sample.getPath()).toAbsolutePath().toString();
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
URL sample = ReaderTest.class.getResource("/sample.csv");
String path = new File(sample.getPath()).getAbsolutePath();
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows 7 Enterprise SP1 (build 7601)
A DESCRIPTION OF THE PROBLEM :
Paths.get is not handling windows paths returned by for example: ...getResource("/resource.txt").getPath();
In that case call for Paths.get will throw exception:
java.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:/...
On Windows systems this call:
...getResource("/resource.txt").getPath();
returns path beginning with "/C:/..".
Such path representation is fully accepted by, for example File class but Paths.get is throwing exception.
Removing first character "/" is helping but in such case we will get error on *nix systems as we remove root.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
On windows system get any resource path using getResource().getPath() and try to pass it to Paths.get method.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Get correct absolute path to resource.
ACTUAL -
java.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:/...
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
URL sample = ReaderTest.class.getResource("/sample.csv");
String path = Paths.get(sample.getPath()).toAbsolutePath().toString();
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
URL sample = ReaderTest.class.getResource("/sample.csv");
String path = new File(sample.getPath()).getAbsolutePath();