Why does Path.getParent() return null?

Alan Bateman Alan.Bateman at oracle.com
Thu Feb 6 12:53:53 PST 2014


On 06/02/2014 18:12, Paulo Levi wrote:
> I'm curious about the reason for not having a special empty path for 
> the case where the parent doesn't exist instead of returning null.
>
> There is quite a bit of code on my experience that has to check for 
> null, when they only call get parent even once, while if it returned a 
> special null empy-space object they would never have to. Even 
> Path.get("", "somedir") ignores the whitespace so it could use that 
> has a representation. Or is the problem that that is already taken for 
> current directory in the path implementation (although i've found that 
> it doesn't have that effect on the get ).
The empty path is specified so that accessing it is equivalent to 
accessing the default directory.

I didn't get your point about Paths.get("", "somedir") as the parameters 
are used to form a path-string. The javadoc details how empty Strings 
are handled. Are you suggesting there is an inconsistency?

>
> Also, i'd like to know if that method will be annotated with a 
> @CheckForNull or similar on the jdk.
Sorry, there isn't an equivalent annotation in the JDK.

-Alan


More information about the nio-discuss mailing list