On Wed, 15 Jul 2026 22:43:24 GMT, Phil Race <[email protected]> wrote:

>> Update code in the package `sun.font` to make use of the `instanceof` 
>> pattern variable. Includes `equals` methods and a few methods using 
>> `ClassCastException` for flow control.
>> 
>> While looking through this code, I've noticed a few pre-existing suspicious 
>> differences between `equals` and `hashCode` implementations, but have not 
>> made any functional changes to fix this (best to address separately, if 
>> needed).
>> 
>> Tests checked locally on Linux, Windows and macOS:
>> - make test TEST="jtreg:test/jdk/java/awt/font"
>> - make test TEST="jtreg:test/jdk/java/awt/Graphics2D/DrawString"
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> src/java.desktop/macosx/classes/sun/font/CFont.java line 310:
> 
>> 308:          }
>> 309:          return o instanceof Font2D other &&
>> 310:              other.getStyle() == this.getStyle();
> 
> I'm not sure what value this adds in this case and the existing code is 
> easier to follow .. but up to you ...

Yeah the wider context makes this safe either way, but I liked the more obvious 
local cast safety assurance. I don't feel too strongly about it though, and can 
change it if you or Prasanta do.

> src/java.desktop/share/classes/sun/font/CompositeFont.java line 305:
> 
>> 303:                     Font2D f2d = fm.findFont2D(componentNames[slot],
>> 304:                                                style,
>> 305:                                                
>> FontManager.PHYSICAL_FALLBACK);
> 
> This is OK, since I doubt it makes any difference today, but back in early 
> JDKs I believe it was cheaper to just do the cast in cases where it was 
> extremely unlikely you'd need to catch an exception and this was in an early 
> start up code path.

Ah, makes sense. Thanks for the info!

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

PR Review Comment: https://git.openjdk.org/jdk/pull/31702#discussion_r3591430942
PR Review Comment: https://git.openjdk.org/jdk/pull/31702#discussion_r3591431273

Reply via email to