Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8334434

MutableBigInteger's methods addShifted and addDisjoint are broken

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      JDK 22.0.1

      A DESCRIPTION OF THE PROBLEM :
      MutableBigInteger's methods addShifted(MutableBigInteger addend, int n) and addDisjoint(MutableBigInteger addend, int n) implicitly assume that (addend.offset + addend.intLen == addend.value.length)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      MutableBigInteger a = new MutableBigInteger();
      MutableBigInteger b = new MutableBigInteger(new int[] { 1, 0, 0, 0, 0, 1, 0 });
      a.addDisjoint(b, 4); // or a.addShifted(b, 4);

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      a.offset == 0 && a.intLen == 8 && Arrays.equals(a.value, new int[] { 1, 0, 0, 0, 0, 0, 0, 0 })
      ACTUAL -
      a.offset == 0 && a.intLen == 8 && Arrays.equals(a.value, new int[] { 1, 0, 0, 0, 0, 1, 0, 0 })

      CUSTOMER SUBMITTED WORKAROUND :
      In MutableBigInteger.java replace the instructions
      for addShifted:
      - in line 818 -> int bval = y < addend.intLen ? addend.value[y+addend.offset] : 0;
      - in line 837 -> int bval = y < addend.intLen ? addend.value[y+addend.offset] : 0;

      for addDisjoint:
      - in line 889 -> int len = Math.min(y, addend.intLen);

      FREQUENCY : occasionally


            rgiulietti Raffaello Giulietti
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: