Recent Java 9 commit (e5b66323ae45) breaks fsync on directory
Francis Galiegue
fgaliegue at gmail.com
Sat May 16 17:30:34 UTC 2015
Hello,
On Sat, May 16, 2015 at 6:48 PM, Robert Muir <rcmuir at gmail.com> wrote:
[...]
>
> I don't understand the tradeoff being made here. The JDK will deliver
> ... a little bit earlier exception to morons trying to read bytes from
> a directory, at the cost of damaging impact to user's data for
> everyone else? What kind of tradeoff is that?
>
That's a little harsh (I'm the "moron" here).
The thing is that you don't always get the choice of your inputs and
if I happen to be given a string which turns out to be a path to a
directory, it is expected that opening an `OutputStream` to it will
fail. In fact, I'd even go as far as saying that introducing an
IsDirectoryException would be pretty much ideal here.
As to a new API, well, why not StandardOpenOption.DIRECTORY?
O_DIRECTORY has existed for open(2) since POSIX.1-2008 (says open(2)),
and it is even specified that if the path is not a directory the
failure is ENOTDIR. Excellent, we have NotDirectoryException already.
But at the core of the matter I disagree with your basic premise. To
me, and to 100-epsilon% of users for that matter, it is perfectly
logical that opening a stream to a directory should fail before you
even attempt to read().
Regards,
--
Francis Galiegue, fgaliegue at gmail.com, https://github.com/fge
JSON Schema in Java: http://json-schema-validator.herokuapp.com
Parsers in pure Java: https://github.com/fge/grappa
More information about the nio-dev
mailing list