RFR: 5041655: (ch) FileLock: negative param and overflow issues [v6]

Alan Bateman alanb at openjdk.java.net
Thu Feb 10 20:10:15 UTC 2022


On Thu, 10 Feb 2022 19:33:16 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> src/java.base/share/classes/java/nio/channels/FileChannel.java line 1005:
>> 
>>> 1003:      *         A value of zero means to lock all bytes from the specified
>>> 1004:      *         starting position to the end of the file, regardless of whether
>>> 1005:      *         the file is subsequently extended or truncated
>> 
>> This looks okay but I think we will need to say something about the return FileLock object. It may be that we need to add text to the method description to say that a FileLock with size "Long.MAX_VALUE - position" is returning when called with a size of 0. What do you think?
>
> I had wondered about adding that:
> 
> -     * Long#MAX_VALUE}.
> +     * Long#MAX_VALUE}.  If a lock is created with a valid {@code position}
> +     * and a {@code size} parameter of zero, then a lock of size
> +     * {@code Long.MAX_VALUE - position} is returned.

Good.

>> src/java.base/share/classes/java/nio/channels/FileLock.java line 269:
>> 
>>> 267:      * <p> If {@code size} is negative, {@code false} is returned regardless
>>> 268:      * of the value of {@code position}.
>>> 269:      *
>> 
>> This is okay but maybe it should move to the "@returns" description. The "@returns" description states the condition when true is returned. We could add "false if size is negative of the lock range does not overlap". Try it and see if it looks a bit better.
>
> I think it does look better:
> 
> -     * @return  {@code true} if, and only if, this lock and the given lock
> -     *          range overlap by at least one byte
> +     * @return  {@code true} if this lock and the given lock range overlap
> +     *          by at least one byte; {@code false} if {@code size} is
> +     *          negative or the lock range does not overlap this lock

Good.

-------------

PR: https://git.openjdk.java.net/jdk/pull/7254


More information about the nio-dev mailing list