-
Notifications
You must be signed in to change notification settings - Fork 36
Description
See #2416 but in short @lukehutch mentioned:
"As an example of what could go wrong, imagine a project root at MyProject/source that has a symlink from MyProject/source/com/xyz/package to MyOtherProject/source/com/xyz/package. Calling getCanonicalPath() will cause the source links to be based in MyOtherProject, while the source root is still in MyProject (because the source root occurs above the symlink).
I think the right thing to do is to never follow symlinks when absolutizing paths. You still need to handle ".." etc.
The "One Right Way" to handle paths in JDK >= 1.7 is using Path, not File. I recently switched a bunch of my own code from File to Path, and it's significantly nicer, more robust, more portable and safer to do things the Path way.
In this case, I think what you want is Path.toRealPath(LinkOption.NOFOLLOW_LINKS)."