On Tue, 28 May 2024 19:13:50 GMT, Jorn Vernee <jver...@openjdk.org> wrote:
>> Pavel Rappo has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Fix incorrect utf16 hashCode adaptation > > src/java.base/share/classes/jdk/internal/util/ArraysSupport.java line 252: > >> 250: return switch (length) { >> 251: case 0 -> initialValue; >> 252: case 1 -> 31 * initialValue + (int) a[fromIndex]; > > Suggestion: > > case 1 -> 31 * initialValue + (int) a[fromIndex]; // sign > extension To be honest, I don't think that this cast is needed. A better solution than to add a comment would be to delete all `(int)` casts from new `hashCode*` methods of `ArraysSupport`. Those `(int)` casts migrated from `hashCode` methods of `Arrays` where there were used if neither of two `+` operands were of type `int`. But in `ArraysSupport` it's no longer the case: `31 * initialValue` is always `int` because `initialValue` is. So, `a[fromIndex]` is promoted to `int` by the virtue of https://docs.oracle.com/javase/specs/jls/se22/html/jls-5.html#jls-5.6. For more confidence, consider that the `private static int hashCode` methods (implementation) of `ArraysSupport` do not have those casts. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/19414#discussion_r1618835934