RFR: JDK-8297332: Remove easy warnings in base

John Hendrikx jhendrikx at openjdk.org
Mon Nov 21 20:07:27 UTC 2022


On Mon, 21 Nov 2022 19:32:01 GMT, Kevin Rushforth <kcr at openjdk.org> wrote:

>> modules/javafx.base/src/test/java/test/util/memory/JMemoryBuddy.java line 123:
>> 
>>> 121: 
>>> 122:         if (weakReference.get() == null && counter < steps / 3) {
>>> 123:             int percentageUsed = (steps - counter) / steps * 100;
>> 
>> I suspect this will not produce a desired result.
>> Perhaps it should be 
>> (int)(100.0 * (steps - counter) / steps);
>
> Removing the `(int)` cast is a behavior-neutral change. What you are pointing out does look a bug, but it is unrelated to this cleanup, so should be filed and fixed separately.

Yeah, this looks like a bug, as `(steps - counter) / steps` which are all `int`s will likely always result in `0`.  The cast removal here however does not alter the calculation, but does point to an error in the author's thought process.  The result is however only used in the log message to inform of a problem, and so the logic is not otherwise affected.

I can file a separate issue for this, unless we can agree to fix it as part of this clean-up.

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

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


More information about the openjfx-dev mailing list