exists and notExists

Alan Bateman Alan.Bateman at Sun.COM
Tue May 27 07:35:13 PDT 2008


Elliotte Harold wrote:
> :
> But what is gained? I still don't understand in what circumstances 
> notExists() will tell you something that !exists() does not. Can you 
> please clarify when
>
> !path.exists() might return a different answer than path.notExists()?
>
> Might they both return false if the existence cannot be determined?
Correct! If we cannot determine if the file exists then both methods 
would return false as documented.

>
> If so, I'd argue that the non-Aristotelian logic here is likely to be 
> deeply confusing. (It's certainly confusing me.) Better solutions 
> would be to either
>
> 1. Use an enumerated return type rather than a boolean that has three 
> states: exists, not exists, unknown.
>
> or
>
> 2. Throw an IOException if the existence cannot be determined.
>
> I'm not sure which I prefer. I think #2 is probably easier, but I'm 
> not sure of that. Regardless the current scheme is just asking for 
> confusion.
>
The motivation for these two convenience methods was to make testing for 
file existence to be very easy. It wasn't intended to be confusing so 
I'm glad you've brought it up.

-Alan.



More information about the nio-discuss mailing list