RFR: JDK-8297413: Remove easy warnings in javafx.graphics [v4]

Nir Lisker nlisker at openjdk.org
Mon Dec 5 21:57:27 UTC 2022


On Mon, 5 Dec 2022 21:40:40 GMT, John Hendrikx <jhendrikx at openjdk.org> wrote:

>> modules/javafx.graphics/src/main/java/com/sun/javafx/font/PrismFontFile.java line 586:
>> 
>>> 584:                 ascent = -(float)hhea.getShort(4);
>>> 585:                 descent = -(float)hhea.getShort(6);
>>> 586:                 linegap = hhea.getShort(8);
>> 
>> interesting: why not on the previous 2 lines?  isn't
>> 
>> `-(float)shortValue == (float)(-shortValue)` ?
>
> Almost, but not quite.  If the `short` is -32768 than negating it would still be -32768.
> 
> If you write it the other way around though, it might get promoted to `int` first anyway, and the point is moot, I would have to test to make sure.

As John explained, the minus sign makes the difference. A `short` has the range of -32,768 to 32,767. If `getShort` returns -32,768, then -(-32,768) is not in the range (32,768 is non-representable). Therefore, you first need to widen it to a type that does include 32,768, and only then negate.

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

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


More information about the openjfx-dev mailing list