RFR: 6742362: JComponent.setFont() font comparison is not correct
Prasanta Sadhukhan
psadhukhan at openjdk.java.net
Wed Feb 23 04:10:50 UTC 2022
On Tue, 22 Feb 2022 17:23:50 GMT, Phil Race <prr at openjdk.org> wrote:
>> Font comparison in JComponent.setFont() uses `font != oldFont` check which is not correct as per Object equality essence. The correct way of checking font equality is to use "equals" as is done in [GlyphLayout](https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/sun/font/GlyphLayout.java#L144) , [StandardGlyphVector](https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/sun/font/StandardGlyphVector.java#L657) etc
>>
>> Existing jtreg, jck test are green.
>
> What Graphics.setFont() says is irrelevant to this.
> Looking at Component.java and Container.java which you need to since super.setFont(f) is called by both JComponent.setFont() and Container.setFont() "==" and "!=" are used there so this would be inconsistent.
> You'd need to take a holistic look at all of these together and make risky changes
> So I'm not sure we should change this. It might just cause unexpected regressions.
> And see for example : https://github.com/openjdk/jdk/pull/7313 so we know Font.equals() isn't perfect.
Thanks for the feedback @prrace on this. I see in some places `==` is used and some places `.equals` and since a JBS issue existed on this so wanted to initiate a discusssion by raising PR..Since there is no proof of `.equals `benefit, I will close this JBS as Won't Fix
-------------
PR: https://git.openjdk.java.net/jdk/pull/7571
More information about the client-libs-dev
mailing list