A relative path cannot be constructed if only one of the paths have a root component. Where both paths have a root component then it is implementation dependent if a relative path can be constructed.
It says it is "implementation dependent", so no, but making some assumptions, you can check if they share the same root and file system.
getRoot() returns null if the path has no root component, otherwise
/ for Linux-like OS's and e.g.
C:\ for Windows. If the other path has a different root (e.g.
relativize() will fail.
Not perfect solution, since we don't know what the "implementation" thinks, but close enough?