Failing test case DataSourceTest#testFileName (Windows OS)
Test DataSourceTest#testFileName fails on a Windows OS with following error:
java.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:/[..]
On line:
try (InputStream is = ds.getOpener().openStreamOnce();
The problem is that the name given as input file name in DataSource ds = new DataSource(url.toURI().getPath());
starts with a "/".
It seems to be a classical problem with Windows-formed path String when calling URI.getPath()
(see https://stackoverflow.com/questions/9834776/java-nio-file-path-issue).
For example, trying the following will fail on Windows with the same exception: Paths.get(url.toURI().getPath());
While Paths.get(url.toURI())
will work and return a properly-formed path (i.e. without the leading "/" character).
Problem is easily solved by replacing the DataSource filename from:
DataSource ds = new DataSource(url.toURI().getPath());
to
DataSource ds = new DataSource(Paths.get(url.toURI()).toString());
I don't think it's an Orekit issue, in my opinion Windows developers should make sure the filename given in input is properly formed.
It's not Orekit's job to check that. Furthermore, the exception is sufficiently detailed for a developer to point out where the problem comes from.
Note that we could also provide a DataSource constructor based on a URI object:
public DataSource(final URI uri) {
this(Paths.get(uri).toString(), () -> Files.newInputStream(Paths.get(uri)));
}
That would prevent developers from falling into this apparently classical trap.