Announcement Announcement Module
No announcement yet.
java.lang.VerifyError: {method name here} Inconsistent stack height 1 != 0 Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • java.lang.VerifyError: {method name here} Inconsistent stack height 1 != 0


    I'm trying to use Spring with AspectJ, at first, just to do dependency injection. It's a very simple (proof-of-concept) Java standalone application.

    If this is not the right place to ask this question, please, let me know.

    I'm getting this strange error: java.lang.VerifyError: {method name here} Inconsistent stack height 1 != 0
    Looks like AspectJ is having some problems with Generics. I removed the first method it pointed, and then it pointed this one (a constuctor actually). What they have in common is the use of Generics.

    I read the entire Chapter 6 of Spring Manual and twice the topic "Load-time weaving with AspectJ in the Spring Framework". I also did some research on the (few) google topics I found about the exception, read the Load-time weaving chapter on AspectJ manual and couldn't solve the problem.

    I'm using Java 1.5, Spring 2.5 and AspectJ from dependencies of this Spring version.

    The relevant part of my configuration is:

    The class I want AspectJ to weave has the @Configurable annotation and one @Autowired attribute. This is the only class where I want weaving.

    The class where problem shows up doesn't have @Configurable annotation.

    I added the -javaagent:./lib/aspects/spring-agent.jar to my JVM initialization.

    The output/stacktrace I get is the following:

    [[email protected]] info AspectJ Weaver Version 1.5.4 built on Thursday Dec 20, 2007 at 13:44:10 GMT
    [[email protected]] info register classloader [email protected]
    [[email protected]] info using configuration file:/C:/Dev/Java/workspacebol/TestThreads/lib/spring-aspects.jar!/META-INF/aop.xml
    [[email protected]] info register aspect org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect
    [[email protected]] info register aspect org.springframework.transaction.aspectj.AnnotationTransactionAspect
    [[email protected]] info processing reweavable type org.springframework.transaction.aspectj.AbstractTransactionAspect: org\springframework\transaction\aspectj\AbstractTransactionAspect.aj
    [[email protected]] info processing reweavable type org.springframework.transaction.aspectj.AnnotationTransactionAspect: org\springframework\transaction\aspectj\AnnotationTransactionAspect.aj
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageService' defined in file [C:\Dev\Java\workspacebol\TestThreads\bin\appcontext.xml]: Initialization of bean failed; nested exception is java.lang.VerifyError: (class: com/mycompany/framework/service/MessageService$$EnhancerByCGLIB$$6dd4e683, method: unique signature: ()Lcom/mycompany/framework/entity/AbstractEntity;) Inconsistent stack height 1 != 0
    	at Method)
    	at com.mycompany.framework.thread.Main.getContext(
    	at com.mycompany.framework.thread.Main.main(
    Caused by: java.lang.VerifyError: (class: com/mycompany/framework/service/MessageService$$EnhancerByCGLIB$$6dd4e683, method: unique signature: ()Lcom/mycompany/framework/entity/AbstractEntity;) Inconsistent stack height 1 != 0
    	at java.lang.Class.getDeclaredMethods0(Native Method)
    	at java.lang.Class.privateGetDeclaredMethods(
    	at java.lang.Class.getDeclaredMethod(
    	at net.sf.cglib.proxy.Enhancer.getCallbacksSetter(
    	at net.sf.cglib.proxy.Enhancer.setCallbacksHelper(
    	at net.sf.cglib.proxy.Enhancer.setThreadCallbacks(
    	at net.sf.cglib.proxy.Enhancer.createUsingReflection(
    	at net.sf.cglib.proxy.Enhancer.firstInstance(
    	at net.sf.cglib.core.AbstractClassGenerator.create(
    	at net.sf.cglib.proxy.Enhancer.createHelper(
    	at net.sf.cglib.proxy.Enhancer.create(
    	at org.springframework.aop.framework.Cglib2AopProxy.getProxy(
    	at org.springframework.aop.framework.ProxyFactory.getProxy(
    	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(
    	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(
    	... 14 more
    Does anyone have a clue on what is going on?

    If you need more information just ask me.

    Thanks in advance,

    Eduardo Simioni.

  • #2

    You have hit something discussed in the AspectJ bug . Basically, CGLIB produces bytecode that contains a strange bit of stack manipulation that AspectJ does not handle - the bytecode is valid but unusual. In generated methods exhibiting this behaviour the methods in question contain multiple RETURN instructions (in the bytecode) but the stack is not the same at each return (CGLIB decided not to add enough POPs before each return). When AspectJ implements after advice, it changes all the returns to point to one place, where the advice is called and then there is a final return from there. Because of this rewrite that changes all returns to jump to a location, there are now multiple routes to a bytecode that will have differing stack contents when arriving at that jump destination - this violates the verifier and gives inconsistent stack height. The solution is to avoid weaving the CGLIB code, you shouldn't need to anyway.

    You do this by including something like this in the aop.xml:

    <exclude within="*..*CGLIB*" />


    • #3
      Thanks a lot, it solved the problem!

      I wouldn't have found out alone as I'm new to AspectJ.

      I have another question, an easier one, I guess.

      I had to change aop.xml inside spring-aspects.jar cause it's the only aop.xml being loaded. I have another aop.xml in my classpath but it's being ignored.

      Is there a way to have them both loaded or this behavior is normal?

      Thanks again,

      Eduardo Simioni.


      • #4
        Where in classpath is your aop.xml? It should be in a META-INF directory that is on the classpath.



        • #5
          It is inside a META-INF directory. I thought it would be loaded cause the manual says that.


          • #6
            I could manage it to work.

            I had put it inside a META-INF directory and made this a source directory in the Eclipse project. This way it doesn't work so I created a META-INF directory inside a source directory. Now everything is fine.


            Eduardo Simioni.