Directly from this API:
resolve
Path resolve(Path other)
Resolve the given path against this path.
If the other parameter is an absolute path then this method trivially returns other. If other is an empty path then this method trivially returns this path. Otherwise this method considers this path to be a directory and resolves the given path against this path. In the simplest case, the given path does not have a root component, in which case this method joins the given path to this path and returns a resulting path that ends with the given path. Where the given path has a root component then resolution is highly implementation dependent and therefore unspecified.
(emphasis mine)
There is a little of a contradiction here, first they say:
If the other parameter is an absolute path then this method trivially returns other.
and then they say:
Where the given path has a root component then resolution is highly implementation dependent and therefore unspecified.
Does not an absolute path have to include a root component in order to be such? Thanks in advance.
The short answer to your question is no, an absolute path does not need to have a root component, however, depending on the provider, it might.
If we look at the source code for UnixPath, we see that, indeed, if it is an absolute path, then it will return a root component, and it will only return a root component if it is an absolute path.
However, there is no requirement that it be implemented in this way. It is, theoretically at least, possible for getRoot() to return something, and for isAbsolute() to return false. In this then the results are undefined. Or, to put it in a truth map form:
Result of resolve() when:
getRoot()==null getRoot()!=null
isAbsolute()==true defined defined
isAbsolute()==false defined undefined
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With