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

Alan Bateman alanb at openjdk.java.net
Thu Feb 17 13:28:10 UTC 2022


On Fri, 11 Feb 2022 21:25:04 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: Fix problem exposed by modified lock tests

src/java.base/share/classes/java/nio/channels/FileLock.java line 286:

> 284:             // the sum of this.position and this.size overflows the range of
> 285:             // long hence their mathematical sum is greater than position
> 286:         }

I think it would be a bit clearer if you move the comment "This is below that" to above the try as something "Test if this is below that". Same for the test to see if that is below this.

src/java.base/share/classes/sun/nio/ch/SimpleAsynchronousFileChannelImpl.java line 184:

> 182:             throw new NonWritableChannelException();
> 183: 
> 184:         long len = size != 0 ? size : Long.MAX_VALUE - Math.max(0, position);

In other places, the changes just checks if size is 0 and set it to Long.MAX_VALUE - Math.max(0, position). This avoids having both "len" and "size" and avoids potential mistakes. Can we do the same here and in the Windows implementation?

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

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


More information about the nio-dev mailing list