JDK-8293039 : Integer.reverse produces incorrect results
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 20
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2022-08-29
  • Updated: 2022-08-30
  • Resolved: 2022-08-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 20
20Resolved
Related Reports
Duplicate :  
Relates :  
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++;
    }
  }
}
Comments
Issue reported is related to incorrect constant folding which is addressed by following Pull request. A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/9987 Date: 2022-08-23 17:58:39 +0000
30-08-2022

ILW = same as JDK-8291649 = P2
29-08-2022

[~jbhateja], please take a look.
29-08-2022