Tr : FileChannel doc
Jeff Hain
jeffhain at rocketmail.com
Tue Oct 2 11:45:27 PDT 2012
Extending my reply.
>the order consideration is for these (exceptional) cases.
More generally, knowing the precise nature and order of tests branching to different
visible behaviors (exceptional or not), if applicable (determinism), makes it easier
to understand how the user code can behave, and removes the need to handle
otherwise expectable cases.
There is a balance between being precise and not over-constraining interfaces,
but in a lot of cases that shouldn't hurt to be that precise.
Taking care to specify it also helps to figure out and avoid weird cases while doing
implementations.
For example, FileChannelImpl.truncate(long) contains:
if (size > size())
return this;
if (!writable)
throw new NonWritableChannelException();
if size == size() or size > size(), no truncation occurs, but in one case
NonWritableChannelException might be thrown and in the other not.
It also shouldn't cause much overhead for exceptions, with the convention
of declaring them in the priority order they are thrown (possibly with multiple
declarations for a same class of exception?).
>makes mocks/tests easier.
Actually any code that makes use of it.
-Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20121002/7e83d74b/attachment.html
More information about the nio-dev
mailing list