ENOTDIR - NotDirectoryException or FileSystemException ?
Jim Gish
jim.gish at oracle.com
Thu Nov 15 07:20:52 PST 2012
Moving a discussion between Alan and me here that was on core-libs-dev.
In short, I'm suggesting that
UnixException.translateToIOException(File,String) check for
UnixConstants.ENOTDIR and throw a NotDirectoryException instead of the
more general FileSystemException.
On 11/15/2012 06:48 AM, Alan Bateman wrote:
>
>>
>> Exactly -- that's my point. This is one of those cases. You're
>> trying to create a new file in a directory, but the file you
>> specified isn't a directory - it's a plain file. The error code
>> coming back is ENOTDIR and so what you get is the more general
>> FileSystemException with "Not a directory" as the error message, when
>> in fact, we could throw NotDirectoryException if we'd simply check
>> for errno of ENOTDIR in the first place along with the other checks
>> being done in UnixException translateToIOException(File,String).
> This isn't an obvious as it might seem because having ENOTDIR always
> map to DirectoryNotEmptyException may cause that exception to be
> thrown in other cases too. Additionally, this specific exception was
> intended for cases where you attempt to do something on a directory
> but it turns out the file is not a directory, this is subtly different
> to the case here. So we need to separate this one, I think the
> FileSystemException that you are seeing now is reasonable.
>
I assume you meant to say NotDirectoryException, above. I realize that
it might be thrown in other cases, but seems appropriate. I'm fine with
it staying as FileSystemException, but would like to understand this
thoroughly. The only cases I can see breaking are those that expect the
more general FileSystemException and are counting on the message being
"Not a directory". Those would break /unless /NotDirectoryException
also carried the message "Not a directory", which we can't do since
there are currently other messages being used, such as the path in error.
You say "this specific exception was intended for cases where you
attempt to do something on a directory but it turns out the file is not
a directory". Isn't that what we're doing in this case? We're
attempting to create a file in the path specified (which is not, as it
turns out, a directory).
Thanks,
Jim
> -Alan
--
Jim Gish | Consulting Member of Technical Staff | +1.781.442.0304
Oracle Java Platform Group | Core Libraries Team
35 Network Drive
Burlington, MA 01803
jim.gish at oracle.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20121115/401263df/attachment.html
More information about the nio-dev
mailing list