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

Alan Bateman alanb at openjdk.java.net
Sun Feb 6 16:49:07 UTC 2022


On Sat, 5 Feb 2022 00:17:46 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Add an implementation note to `java.nio.channels.FileLock.overlaps(long,long)` indicating that the method does not check its parameters. Adding such checks would be an incompatible change.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   5041655: Remove implNote; add special cases for negative and zero sizes; handle overflow; handle zero size on Windows; add test

Changing the overlaps method to return false when size is negative is good. The updated range check that allows for the position to be negative looks good too. The compatibility impact should be negligible for this part.

Changing the lock method to treat size==0 as Long.MAX_VALUE-position is the behavior on some platforms already and is implementable in a consistent way on all platforms. So on the surface it's probably the right thing to do. However as proposed, it creates a FileLock with size == 0 that will not overlap with any other lock. To work correctly, it will need to be "promoted" to Long.MAX_VALUE-position before creating the FileLock. That will allow you to drop the change to the native code from the patch.

I have several comments on the javadoc changes but I think we need to get to agreement on size=0 first.

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

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


More information about the nio-dev mailing list