The issue is very close to being resolved. Attila's suggestion was near perfect. It has the following problem though:
If File f was constructed using a relative path (e.g. new File("dir") where dir is a directory within the current one), then getParent() will return null. So far so good. However, if dir is a directory whose ancestors include folders with long names (e.g. "Documents and Settings"), then under 1.6.0_14 on Windows XP SP3, the canonical path is something like
C:\Documents and Settings\Administrator\Desktop\test\directory
And the absolute path is something like
They are unequal, so isSymlink will return true. Which is incorrect. To avoid this problem, we should obtain f's absolute path before we try to get its parent. That is, inside isSymlink,
should be replaced with
And similarly file.getParentFile() should become file.getAbsoluteFile().getParentFile().
Doing this will ensure that we'll obtain f's parent, even if f is specified with a relative file name. This, combined with Attila's fix, will avoid oddities like the DOS names above somewhere in the ancestral hierarchy.