Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 543230

Summary: [12] Inconsistent stackmap frames with switch expression
Product: [Eclipse Project] JDT Reporter: Jay Arthanareeswaran <jarthana>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: manoj.palat
Version: 4.10   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard:

Description Jay Arthanareeswaran CLA 2019-01-08 01:33:07 EST
The following code throws an exception when run:
public class Switch {
	public static long foo(String s) {
		long promoted = switch(s){
			case "1" -> 1; // trouble here!
			default -> 0;
		};
		return promoted;
	}
	public static void main(String[] args) {
		System.out.println(foo("1"));
	}
}

The error is:
Error: Unable to initialize main class Switch
Caused by: java.lang.VerifyError: Inconsistent stackmap frames at branch target 40
Exception Details:
  Location:
    Switch.foo(Ljava/lang/String;)J @6: lookupswitch
  Reason:
    Current frame's stack size doesn't match stackmap.
  Current Frame:
    bci: @6
    flags: { }
    locals: { 'java/lang/String', top, top, 'java/lang/String' }
    stack: { integer }
  Stackmap Frame:
    bci: @40
    flags: { }
    locals: { 'java/lang/String', top, top, 'java/lang/String' }
    stack: { long, long_2nd }
  Bytecode:
    0000000: 2a59 4eb6 0010 ab00 0000 0022 0000 0001
    0000010: 0000 0031 0000 0012 2d12 16b6 0018 9a00
    0000020: 06a7 0007 0aa7 0004 0940 1fad          
  Stackmap Table:
    full_frame(@24,{Object[#17],Top,Top,Object[#17]},{})
    same_frame(@36)
    same_locals_1_stack_item_frame(@40,Long)
    full_frame(@41,{Object[#17]},{Long,Long})
Comment 1 Manoj N Palat CLA 2019-01-08 01:40:13 EST
@Jay: Codegen is pending - see bug 542838
[Issue raised there specifically is the same]

*** This bug has been marked as a duplicate of bug 542838 ***