On Tue, 1 Sep 2026 20:54:32 GMT, Andy Goryachev <[email protected]> wrote:
>> modules/javafx.graphics/src/main/java/javafx/scene/input/DataFormat.java
>> line 194:
>>
>>> 192:
>>> 193: for (String id : identifiers) {
>>> 194: hash = 31 * hash + id.hashCode();
>>
>> The hash should be `identifiers.hashCode()` to match the `equals` check.
>
> please elaborate - the current implementation complies with the
> hashCode/equals contract (and is effectively unchanged btw).
Two `equals` objects must have the same hashcode. This is not the case here:
`DataFormat#equals` calls `Set#equals`, whose contract says that the elements
need to be equal (order-independent). The current hash function iterates the
elements in an unspecified order, producing order-dependent hashes.
`Set.of("a", "b")` and `Set.of("b", "a")` are `equals` but have different
hashes. By delegating to `Set#hashCode`, we align it with `Set#equals` and have
`Set` worry about matching its contract.
-------------
PR Review Comment: https://git.openjdk.org/jfx/pull/2197#discussion_r3908440729