Redundant condition in java.math.MutableBigInteger#divideMagnitude
Raffaello Giulietti
raffaello.giulietti at oracle.com
Mon Nov 28 12:35:45 UTC 2022
I can confirm that testing that condition is indeed useless
From: core-libs-dev <core-libs-dev-retn at openjdk.org> on behalf of Andrey Turbanov <turbanoff at gmail.com>
Date: Friday, 2022-November-25 at 14:18
To: core-libs-dev <core-libs-dev at openjdk.java.net>
Subject: Redundant condition in java.math.MutableBigInteger#divideMagnitude
Hello.
I noticed that IntelliJ IDEA show warning in the method
java.math.MutableBigInteger#divideMagnitude
here - https://github.com/openjdk/jdk/blob/4f65570204e2d38415e7761bd81660b081eae882/src/java.base/share/classes/java/math/MutableBigInteger.java#L1536
It seems that condition is always 'true'
if (rem.intLen == nlen) {
'rem' and 'nlen' variables are not changed anyhow after this
assignment a few lines above:
int nlen = rem.intLen;
To make sure that it's really true, I've modified source to include else branch:
} else {
throw new AssertionError("Condition 'rem.intLen == nlen' wasn't met.");
}
And all tests from "jdk/java/math" passed.
Can we clean up the code to remove this condition? Code is already
complex enough and each condition makes its reading harder.
It was added as part of performance improvements in
https://bugs.openjdk.org/browse/JDK-7082971
Andrey Turbanov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20221128/aa2d1568/attachment.htm>
More information about the core-libs-dev
mailing list