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

Integer.reverse produces incorrect results

    XMLWordPrintable

Details

    Description

      I'm seeing Integer.reverse behaviour change in recent JDK 20 EA builds, I think the culprit is JDK-8290034.

      $ java -fullversion
      openjdk full version "20-ea+12-790"

      $ java -cp ~/ T
      Exception in thread "main" java.lang.AssertionError: expected Integer.reverse(1) to be -2147483648, but was 128 after 307906 iterations
              at T.main(T.java:9)

      class T {
        public static void main(String[] args) {
          long c = 0;
          int expected = -2147483648;
          while (true) {
            long r = Integer.reverse(1);
            if (r != expected) {
              throw new AssertionError(
                  String.format(
                      "expected Integer.reverse(1) to be %d, but was %d after %d iterations",
                      expected, r, c));
            }
            c++;
          }
        }
      }

      Attachments

        Issue Links

          Activity

            People

              jbhateja Jatin Bhateja
              cushon Liam Miller-Cushon
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: