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

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

    Hi,

    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:

    Code:
    	<context:annotation-config/>
    	<context:spring-configured/>
    	<context:load-time-weaver/>
    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:

    Code:
    [AppClassLoader@1f12c4e] info AspectJ Weaver Version 1.5.4 built on Thursday Dec 20, 2007 at 13:44:10 GMT
    [AppClassLoader@1f12c4e] info register classloader sun.misc.Launcher$AppClassLoader@1f12c4e
    [AppClassLoader@1f12c4e] info using configuration file:/C:/Dev/Java/workspacebol/TestThreads/lib/spring-aspects.jar!/META-INF/aop.xml
    [AppClassLoader@1f12c4e] info register aspect org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect
    [AppClassLoader@1f12c4e] info register aspect org.springframework.transaction.aspectj.AnnotationTransactionAspect
    [AppClassLoader@1f12c4e] info processing reweavable type org.springframework.transaction.aspectj.AbstractTransactionAspect: org\springframework\transaction\aspectj\AbstractTransactionAspect.aj
    [AppClassLoader@1f12c4e] 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 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:445)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:383)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:353)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:400)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:736)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:123)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
    	at com.mycompany.framework.thread.Main.getContext(Main.java:23)
    	at com.mycompany.framework.thread.Main.main(Main.java:10)
    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(Class.java:2427)
    	at java.lang.Class.getDeclaredMethod(Class.java:1935)
    	at net.sf.cglib.proxy.Enhancer.getCallbacksSetter(Enhancer.java:627)
    	at net.sf.cglib.proxy.Enhancer.setCallbacksHelper(Enhancer.java:615)
    	at net.sf.cglib.proxy.Enhancer.setThreadCallbacks(Enhancer.java:609)
    	at net.sf.cglib.proxy.Enhancer.createUsingReflection(Enhancer.java:631)
    	at net.sf.cglib.proxy.Enhancer.firstInstance(Enhancer.java:538)
    	at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:225)
    	at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
    	at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
    	at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:201)
    	at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
    	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:433)
    	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:331)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1266)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:438)
    	... 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
    Hi,

    You have hit something discussed in the AspectJ bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=117854 . 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:

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

    Comment


    • #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.

      Comment


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

        -Ramnivas

        Comment


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

          Comment


          • #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.

            Thanks!

            Eduardo Simioni.

            Comment

            Working...
            X