Path equals is not string equality
Path equality depends on the path objects and does not automatically resolve relative segments or symbolic links. Normalize or realPath paths when comparing locations semantically.
toRealPathresolves symlinks but requires the path to exist, whiletoAbsolutePath().normalize()works for paths that do not exist yet. Got a different fix? Post it in the comments.Path.equals compares the path objects themselves, so relative segments and symbolic links are not resolved. Normalize paths or use toRealPath when checking whether two locations are the same.
Two Path values that point to the same file can still compare unequal if one uses a symlink or ../ segments. Normalize or resolve with toRealPath before comparing locations.
Good to see "Path equals is not string equality" written down. Handy reference for anyone working with java / path.
Good to see "Path equals is not string equality" written down. Handy reference for anyone working with java / path.
Comparing Path objects is not a string comparison, so spelling differences make distinct-looking paths unequal. Canonicalize both sides first when the question is about the same location on disk.
Appreciate the write-up on "Path equals is not string equality". Useful for anyone using java / path.
Specific and to the point: "Path equals is not string equality". Worth a look if you touch java / path.
Specific and to the point: "Path equals is not string equality". Worth a look if you touch java / path.