RFR: 7083187: Class CSS.CssValue is missing implementations of equals() and hashCode() [v17]

Prasanta Sadhukhan psadhukhan at openjdk.org
Thu Jun 8 11:58:18 UTC 2023


On Thu, 8 Jun 2023 11:26:09 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

>> src/java.desktop/share/classes/javax/swing/text/html/CSS.java line 2690:
>> 
>>> 2688:             return val instanceof CSS.LengthValue lu
>>> 2689:                    && span == lu.span
>>> 2690:                    && Objects.equals(units, lu.units);
>> 
>> [The `percentage` field](https://github.com/openjdk/jdk/pull/13405#discussion_r1221932524) must also be part of `equals`:
>> Suggestion:
>> 
>>             return val instanceof CSS.LengthValue lu
>>                    && percentage == lu.percentage
>>                    && span == lu.span
>>                    && Objects.equals(units, lu.units);
>> 
>> You have included it in `hashCode`.
>
> If `percentage` isn't taken into account, the pair `{"margin-top: 100%", "margin-top: 1"}` is considered equal. (And it essentially is; however, I think we should include the `percentage` field, it is part of the object and the behaviour will be different.)
> 
> By the way, this is another quirk of Swing's CSS implementation: in the CSS spec, values without units are considered an error except for a few cases where such usage is specifically allowed.

Updated..

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13405#discussion_r1222934068



More information about the client-libs-dev mailing list