Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 7 - Inconsistent stackmap frames - Need help understanding why solution works

When I compile and run my project in Eclipse with JDK7 or JDK6 all is well. However after I build it using ANT and then tried to run it using the system JDK7, I get the error:

Inconsistent stackmap frames at branch target 25 in method myClass.myMethod() [[Ljava/lang/Object; at offset 14

I've looked everywhere and found a couple of good questions here on StackOverFlow:

  • Java 7 JVM VerifyError in Eclipse
  • Akka Actors fails, VerifyError: Inconsistent stackmap frames at branch target

Both basically suggest to add -XX:-UseSplitVerifier as a JVM option which did solve the issue. I still don't fully understand why but apparently this bug report is suppose to help. Unfortunately I still don't get it...

I did notice on one of the questions that someone was using Aspect oriented programming, which made me think I'm using Guice (Google's DI framework) which could cause the issue but I can't see how. It's suppose to support JDK7.

I'm also using Proguard but that too is suppose to work with JDK7.

Anyways at this point I have no idea why this workaround is working other than it's basically falling back to the previous JDK (in this case JDK6) version when some part of the code is trying to play with the byte code (which is why I think it's related to the DI) code. But I'm still not able to make the proper link. And I could also be way off!!

If someone could explain what's going or why this happens I would be extremely appreciative. Also I really hate having to use a workaround as this isn't what I consider a long term solution.

like image 422
Stephane Grenier Avatar asked Oct 22 '22 07:10

Stephane Grenier


1 Answers

As of Java 7, compiled bytecode has to contain additional StackMapTable attributes. These help the verifier inside the JVM to check that classes are soundly constructed, at class loading time. Earlier versions of Java are more lenient, falling back on the slower verification without attributes.

Tools that modify the original compiled bytecode (ProGuard right after the compilation, AOP frameworks right before the execution,...) need to update the attributes consistently with the modified code. If they fail to do so, you'll get the error message "Inconsistent stackmap frames".

ProGuard should perform this preverification fine; I'm not aware of any problems with it. If you still see the error without applying ProGuard, the problem must lie with the DI or AOP.

like image 192
Eric Lafortune Avatar answered Oct 27 '22 11:10

Eric Lafortune