Redundant condition in java.math.MutableBigInteger#divideMagnitude

Andrey Turbanov turbanoff at gmail.com
Fri Nov 25 13:17:45 UTC 2022


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


More information about the core-libs-dev mailing list