5
votes

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:

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.

1
" It's suppose to support JDK7. " - maybe its support is buggy. Have you searched the Guice issue tracker / groups / lists?Stephen C
Haven't been able to find anything in terms of bugs in their issue trackerStephane Grenier
My guess would be that in java7 they've added more aggressive byte code verifying checks and whatever guice is doing with the byte code to do its dependency injection does not work with those checksDenis Tulskiy
when you say you build with ant, do you run ant from eclipse? It could also be a bug in eclipse's compiler, and if so, try building this code with pure javac, or from NetBeans, for example.Denis Tulskiy
The issue is that it works in eclipse and not with the pure jvm. I also use proguard and thought that might be part of the issue, but that's also suppose to support JDK7Stephane Grenier

1 Answers

3
votes

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.