RFR: 8321429: (fc) FileChannel.lock creates a FileKey containing two long index values, they could be stored as int values

Alan Bateman alanb at openjdk.org
Thu Dec 7 09:28:34 UTC 2023


On Thu, 7 Dec 2023 01:32:45 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> The private `FileKey` fields `dwVolumeSerialNumber`, `nFileIndexHigh`, and `nFileIndexLow` are converted to `int`s to match the number of bits in their native `DWORD` counterparts. The difference in sign appears irrelevant in this case.

src/java.base/windows/classes/sun/nio/ch/FileKey.java line 50:

> 48:     @Override
> 49:     public int hashCode() {
> 50:         return dwVolumeSerialNumber + nFileIndexHigh + nFileIndexLow;

I assume that that it's not too common to use FileChannel.lock to lock many regions of a file so the quality of the hashCode might not b important. However, looking at it now makes me wonder about the addition, maybe it should do the usual multiple by prime and add the next common, as if calling Objects.hashCode.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17009#discussion_r1418656313


More information about the nio-dev mailing list