I have recently upgraded my project to Java 1.8 from 1.7.
I get an exception for inconsistent stackmap for a method in one of my Classes.
Initializing some unassigned local variables in the method resolved it, but can somebody please explain why use of unread variables raise an exception in Java 8, thanks.
It might well be with the eclipse version (Kepler SR 2 20140224-0627) that am using, just curious.
WorkAround
was previously using '--xxSplitVerifier' (in 1.7) or '-noVerify' Jvm arguments before fixing the faulty code.
if compiler preferences in eclipse workspace is unchecked with the option 'preserve unused local variables' it compiles fine with java 8
Method :
Cannot post complete method as its very big and restrained code of the company I'm with.
public synchronized int setData() //sample code
{
int id= 0;
StringBuffer sb; // works if initialized - stringBuffer sb = null;
String name; // works if name = null
if (true) {
sb = new StringBuffer();
} else {
sb = new StringBuffer();
}
stackFrame :
Caused by: java.lang.VerifyError: Inconsistent stackmap frames at branch target 2079
Exception Details: Location: someClass.setData(someClass/Data)I @2079: iload_3
Reason: Type top (current frame, locals[4]) is not assignable to 'java/lang/StringBuffer' (stack map, locals[4])
Current Frame: bci: @98 flags: { } locals: { 'someClass/setData', 'someClass/Data', 'someClass/Data', integer, top, top } stack: { 'someClass/Data' }
Stackmap Frame: bci: @2079 flags: { } locals: { 'someClass/setData', 'someClass/Data', 'someClass/Data', integer, 'java/lang/StringBuffer', 'java/lang/String'} stack: { } Bytecode: 0x0000000: 2bb6 032b 4d03 3e06 bd01 3e59 0313 032f 0x0000010: 5359 0413 0331 5359 0513 0333 533a 0606