Path.resolve (other) java.nio.file.Path method

Directly from this API :

Determination

Path resolution (other path)

Allow this path along this path.

If the other parameter is the absolute path, then this method trivially returns the others. If the other is an empty path, then this method trivially returns this path. Otherwise, this method treats this path as a directory and resolves this path along this path. in The simplest case, a given path does not have a root component in which this method connects the given path to this path and returns the final path that ends with the given path. If this path has a root component, then the resolution is highly implementation dependent and therefore not specified.

(my emphasis)

There is a bit of controversy here, at first they say:

  • If the other parameter is an absolute path, then this method trivially returns the others.

    and then they say:

  • If this path has a root component, then the resolution is highly implementation dependent and therefore undefined.

Should the absolute path include the root component in order to be so? Thanks in advance.

+4
source share
1 answer

The short answer to your question is no, the absolute path should not have a root component, however, depending on the provider, it may.

If we look at the source code for UnixPath , we will see that, indeed, if it is an absolute path, then it will return the root component, and it will return only the root component if it is an absolute path.

However, there is no requirement that it be implemented in this way. Theoretically, at least it is possible for getRoot () to return something, and for isAbsolute () to return false. In this case, the results are undefined. Or, to put this in the form of a map of truth:

Result of resolve() when: getRoot()==null getRoot()!=null isAbsolute()==true defined defined isAbsolute()==false defined undefined 
+2
source

Source: https://habr.com/ru/post/1502452/


All Articles