JDK-8332934 : Do loop with continue with subsequent switch leads to incorrect stack maps
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8,11,17,22,23
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2024-05-20
  • Updated: 2025-05-19
  • Resolved: 2025-05-07
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 25
25 b22Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

$ uname -a
Linux dell-PowerEdge-R740 5.15.0-105-generic #115~20.04.1-Ubuntu SMP Mon Apr 15 17:33:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

$ /path/to/jdk22/bin/javac -version
javac 22

A DESCRIPTION OF THE PROBLEM :
We compiled the following testcase using javac and executed it with the JVM, resulting in the following crash error message (We tried using various versions of javac (1.8, 17, 22), but the issue persists.):

Error: Unable to initialize main class Test
Caused by: java.lang.VerifyError: Inconsistent stackmap frames at branch target 44
Exception Details:
  Location:
    Test.main([Ljava/lang/String;)V @44: iload_2
  Reason:
    Type top (current frame, locals[4]) is not assignable to double (stack map, locals[4])
  Current Frame:
    bci: @16
    flags: { }
    locals: { '[Ljava/lang/String;', top, integer, integer }
    stack: { integer }
  Stackmap Frame:
    bci: @44
    flags: { }
    locals: { '[Ljava/lang/String;', top, integer, integer, double, double_2nd }
    stack: { }
  Bytecode:
    0000000: 083d 063e 0436 04a7 0003 1d07 a1ff f805
    0000010: ab00 0000 0000 001e 0000 0002 0000 0003
    0000020: 0000 001c 0000 0004 0000 001c 1c3c b1  
  Stackmap Table:
    append_frame(@4,Top,Integer,Integer)
    same_frame(@10)
    append_frame(@44,Double)
    chop_frame(@46,1)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac Test.java
java Test

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Infinite loop
ACTUAL -
Crash

---------- BEGIN SOURCE ----------
class Test {
  public static void main(String[] k) {
    int a;
    int b = 5;
    int c = 3;
    do {
      boolean e = true;
      continue;
    } while (c < 4);
    switch (2) {
    case 3:
      double d;
    case 4:
      a = b;
    }
  }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Changeset: 3f6b1777 Branch: master Author: Chen Liang <liach@openjdk.org> Date: 2025-05-07 18:09:23 +0000 URL: https://git.openjdk.org/jdk/commit/3f6b17777ffe59d8981e252891ef2e5beeaf2fdd
07-05-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/25071 Date: 2025-05-06 19:42:47 +0000
06-05-2025

Made another minimal reproducer that only creates 2 variables. These variables and goto are necessary to trigger this problem. Seems the frame for double is not elided in generation (happens if the variable or continue is removed) while the double variable itself is.
06-09-2024

The observations on Windows 11: JDK 8: Failed, crash observed JDK 11: Failed. JDK 17: Failed. JDK 22: Failed. JDK 23ea+14: Failed.
26-05-2024