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

Alan Bateman alanb at openjdk.java.net
Fri Feb 18 15:21:12 UTC 2022


On Thu, 17 Feb 2022 16:49:45 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> 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?
>
> In both cases the `size` parameter is final and cannot be reassigned, so either the parameter has to be made non-final or a new variable has to be used.

Okay, I see it would be disruptive to do that. In that case, let's go with what you have (maybe put parentheses around the size != 0 condition in the ternary to make it a bit clearer).

Overall I think we've got the two original corner cases to a good place with minimal-to-no impact.

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

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


More information about the nio-dev mailing list