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

test failed with unexpected ArithmeticException in Long.divideUnsigned when 1L / 0L

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      A DESCRIPTION OF THE PROBLEM :
      We generate a unit test automatically and it failed with ArithmeticException.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      the unit test case is:
      @Test
        public void test_divideUnsigned_6_119(){

            long long0 = 1L;
            long long1 = 0L;
            Long.divideUnsigned(long0, long1);

        }

      ACTUAL -
      java.lang.ArithmeticException: / by zero

      at java.base/java.lang.Long.divideUnsigned(Long.java:1673)

      ---------- BEGIN SOURCE ----------
      public static long divideUnsigned(long dividend, long divisor) {
              /* See Hacker's Delight (2nd ed), section 9.3 */
              if (divisor >= 0) {
                  final long q = (dividend >>> 1) / divisor << 1;
                  final long r = dividend - q * divisor;
                  return q + ((r | ~(r - divisor)) >>> (Long.SIZE - 1));
              }
              return (dividend & ~(dividend - divisor)) >>> (Long.SIZE - 1);
          }
      ---------- END SOURCE ----------

      FREQUENCY : occasionally


      Attachments

        Activity

          People

            darcy Joe Darcy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: