Redundant condition in java.math.MutableBigInteger#divideMagnitude

Joseph D. Darcy joe.darcy at oracle.com
Mon Nov 28 18:48:23 UTC 2022


Filed https://bugs.openjdk.org/browse/JDK-8297731.

Thanks,

-Joe

On 11/28/2022 4:35 AM, Raffaello Giulietti wrote:
>
> 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/209d6ab1/attachment.htm>


More information about the core-libs-dev mailing list