If path doesn’t have parent directory, File.getParent() will return null.

Found this behavior in a unit test case and in Java Doc, it’s described very clear.

String java.io.File.getParent()

Returns the pathname string of this abstract pathname’s parent, or null if this pathname does
not name a parent directory.
The parent of an abstract pathname consists of the pathname’s prefix, if any, and each
name in the pathname’s name sequence except for the last. If the name sequence is empty
then the pathname does not name a parent directory.

See following test cases,

Just pay attention on it!