<Swing Dev> Suspicious field assignment in StrikeMetrics
Volodin, Vladislav
vladislav.volodin at sap.com
Tue Jan 5 12:14:33 UTC 2021
Hello Andrey,
Nice catch! You can create a bug and prepare a pull request, so maintainers can review it.
What I have just personally noticed, all fields have the type float, so probably instead of "Integer.MIN_VALUE", I would recommend to use "-Float.MAX_VALUE". But since this code is about 13-years old, I don't know if reviewers can accept your PR without additional tests.
Kind regards,
Vlad
-----Original Message-----
From: swing-dev <swing-dev-retn at openjdk.java.net> On Behalf Of Andrey Turbanov
Sent: Dienstag, 5. Januar 2021 12:40
To: swing-dev at openjdk.java.net
Subject: <Swing Dev> Suspicious field assignment in StrikeMetrics
Hello.
I've found suspicious code in constructor sun.font.StrikeMetrics#StrikeMetrics()
StrikeMetrics() {
ascentX = ascentY = Integer.MAX_VALUE;
descentX = descentY = leadingX = leadingY = Integer.MIN_VALUE;
baselineX = baselineX = maxAdvanceX = maxAdvanceY = Integer.MIN_VALUE;
}
As you can see, basLineX field is assigned twice.
Looks like it's supposed to be like this:
baselineX = baselineY = maxAdvanceX = maxAdvanceY = Integer.MIN_VALUE;
Found by SpotBugs
https://spotbugs.readthedocs.io/en/stable/bugDescriptions.html#sa-double-assignment-of-field-sa-field-double-assignment
Andrey Turbanov
More information about the swing-dev
mailing list