RFR: 8289389: Fix warnings: type should also implement hashCode() since it overrides Object.equals() [v4]

Kevin Rushforth kcr at openjdk.org
Fri Jul 22 16:30:33 UTC 2022


On Tue, 19 Jul 2022 15:48:09 GMT, Andy Goryachev <angorya at openjdk.org> wrote:

>> - added missing hashCode() methods
>
> Andy Goryachev has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains five additional commits since the last revision:
> 
>  - 8289389: review comments
>  - Merge remote-tracking branch 'origin/master' into 8289389.hash
>  - 8289389: minimize the impact of collision
>  - 8289389: toExternalForm()
>  - 8289389: implemented missing hashCode()

Looks pretty good now. I noted a couple places that might need a change.

modules/javafx.media/src/main/java/com/sun/media/jfxmediaimpl/NativeMediaAudioClipPlayer.java line 456:

> 454:     @Override
> 455:     public int hashCode() {
> 456:         int h = sourceClip.getLocator().getURI().hashCode();

Is `URI::hashCode()` guaranteed to return a non-zero value? If not, then initializing h to 1 and accumulating this would be better.

modules/javafx.web/src/main/java/com/sun/webkit/graphics/WCRectangle.java line 265:

> 263:     @Override
> 264:     public int hashCode() {
> 265:         int h = Float.floatToIntBits(x);

Best to initialize `h` to 1 and accumulate `x`.

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

PR: https://git.openjdk.org/jfx/pull/821


More information about the openjfx-dev mailing list