JDK-8160699 : java.lang.VerifyError: Inconsistent stackmap frames at branch target
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7,8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86_64
  • Submitted: 2016-06-30
  • Updated: 2025-05-08
  • Resolved: 2016-09-14
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 9
9 b137Fixed
Related Reports
Causes :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
Class compiles but fails to load:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.VerifyError: Inconsistent stackmap frames at branch target 82
Exception Details:
  Location:
    SwitchCompilerErr.switchTo()V @82: new
  Reason:
    Type top (current frame, locals[3]) is not assignable to 'java/lang/String' (stack map, locals[3])
  Current Frame:
    bci: @57
    flags: { }
    locals: { 'SwitchCompilerErr', integer, integer }
    stack: { integer }
  Stackmap Frame:
    bci: @82
    flags: { }
    locals: { 'SwitchCompilerErr', integer, integer, 'java/lang/String' }
    stack: { }
  Bytecode:
    0x0000000: bb00 0259 b700 03b6 0004 3cbb 0002 59b7
    0x0000010: 0003 b600 043d 1bab 0000 0017 0000 0001
    0x0000020: 0000 0000 0000 0011 1205 4ea7 000d bb00
    0x0000030: 0659 1207 b700 08bf 1cab 0000 0000 0019
    0x0000040: 0000 0001 0000 0000 0000 0013 1205 4ea7
    0x0000050: 000d bb00 0659 1207 b700 08bf b1       
  Stackmap Table:
    append_frame(@40,Integer,Integer)
    same_frame(@46)
    same_frame(@56)
    same_frame(@76)
    append_frame(@82,Object[#19])
    chop_frame(@92,1)

        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
        at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
        at java.lang.Class.getMethod0(Class.java:3018)
        at java.lang.Class.getMethod(Class.java:1784)
        at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)


REGRESSION.  Last worked in version 7u76

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_76"
Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile and run supplied code



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
expected to load and execute
ACTUAL -
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.VerifyError: Inconsistent stackmap frames at branch target 82
Exception Details:
  Location:
    SwitchCompilerErr.switchTo()V @82: new
  Reason:
    Type top (current frame, locals[3]) is not assignable to 'java/lang/String' (stack map, locals[3])
  Current Frame:
    bci: @57
    flags: { }
    locals: { 'SwitchCompilerErr', integer, integer }
    stack: { integer }
  Stackmap Frame:
    bci: @82
    flags: { }
    locals: { 'SwitchCompilerErr', integer, integer, 'java/lang/String' }
    stack: { }
  Bytecode:
    0x0000000: bb00 0259 b700 03b6 0004 3cbb 0002 59b7
    0x0000010: 0003 b600 043d 1bab 0000 0017 0000 0001
    0x0000020: 0000 0000 0000 0011 1205 4ea7 000d bb00
    0x0000030: 0659 1207 b700 08bf 1cab 0000 0000 0019
    0x0000040: 0000 0001 0000 0000 0000 0013 1205 4ea7
    0x0000050: 000d bb00 0659 1207 b700 08bf b1       
  Stackmap Table:
    append_frame(@40,Integer,Integer)
    same_frame(@46)
    same_frame(@56)
    same_frame(@76)
    append_frame(@82,Object[#19])
    chop_frame(@92,1)

        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
        at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
        at java.lang.Class.getMethod0(Class.java:3018)
        at java.lang.Class.getMethod(Class.java:1784)
        at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.Random;

public class SwitchCompilerErr {

	private void switchTo() throws Exception {
		int e = new Random().nextInt();
		int m = new Random().nextInt();
		switch (e) {
		case 0:
			String a = "";
			break;
		default:
			throw new Exception("Unknown ");
		}
//		String z = "";
		switch (m) {
		case 0:
			String b = "";
			break;
		default:
			throw new Exception("Unknown ");
		}
	}
	
	public static void main(String[] args) throws Exception {
		new SwitchCompilerErr().switchTo();
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
inserting variable definition in between switch statements prevents this issue


Comments
URL: http://hg.openjdk.java.net/jdk9/jdk9/langtools/rev/6e028413ea08 User: lana Date: 2016-09-21 20:17:37 +0000
21-09-2016

URL: http://hg.openjdk.java.net/jdk9/dev/langtools/rev/6e028413ea08 User: sadayapalam Date: 2016-09-14 14:30:37 +0000
14-09-2016

Smaller test case: public class X { public static void main(String[] args) throws Exception { switch (0) { case 0: String a = ""; break; default: throw new Exception("Unknown "); } switch (0) { case 0: String b = ""; break; default: throw new Exception("Unknown "); } } }
14-09-2016

Eclipse compiles this fine. Reproduced the verify error on JDK 9 tip.
19-07-2016

Test result == 6u45 - Pass 7u76 - Pass 7u80 - Fail 8u0 - Pass 8u52 - Pass 8u60 - Fail 8u92 - Fail 9 ea b-125 - Fail
01-07-2016

This is an regression introduced in 7u80 and 8u60 respectively, Below is the results == -sh-4.1$ /opt/java/jdk1.7.0_76/bin/javac SwitchCompilerErr.java -sh-4.1$ /opt/java/jdk1.7.0_76/bin/java SwitchCompilerErr Exception in thread "main" java.lang.Exception: Unknown at SwitchCompilerErr.switchTo(SwitchCompilerErr.java:13) at SwitchCompilerErr.main(SwitchCompilerErr.java:25) -sh-4.1$ /opt/java/jdk1.7.0_80/bin/javac SwitchCompilerErr.java -sh-4.1$ /opt/java/jdk1.7.0_80/bin/java SwitchCompilerErr Exception in thread "main" java.lang.VerifyError: Inconsistent stackmap frames at branch target 82 Exception Details: Location: SwitchCompilerErr.switchTo()V @82: new Reason: Type top (current frame, locals[3]) is not assignable to 'java/lang/String' (stack map, locals[3]) Current Frame: bci: @57 flags: { } locals: { 'SwitchCompilerErr', integer, integer } stack: { integer } Stackmap Frame: bci: @82 flags: { } locals: { 'SwitchCompilerErr', integer, integer, 'java/lang/String' } stack: { } Bytecode: 0000000: bb00 0259 b700 03b6 0004 3cbb 0002 59b7 0000010: 0003 b600 043d 1bab 0000 0017 0000 0001 0000020: 0000 0000 0000 0011 1205 4ea7 000d bb00 0000030: 0659 1207 b700 08bf 1cab 0000 0000 0019 0000040: 0000 0001 0000 0000 0000 0013 1205 4ea7 0000050: 000d bb00 0659 1207 b700 08bf b1 Stackmap Table: append_frame(@40,Integer,Integer) same_frame(@46) same_frame(@56) same_frame(@76) append_frame(@82,Object[#19]) chop_frame(@92,1) at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2625) at java.lang.Class.getMethod0(Class.java:2866) at java.lang.Class.getMethod(Class.java:1676) at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486) -sh-4.1$ ==
01-07-2016