Announcement Announcement Module
Collapse
No announcement yet.
@AfterThrowing#Throwing argument name 'ex' was not bound in advice arguments Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @AfterThrowing#Throwing argument name 'ex' was not bound in advice arguments

    Hi there,

    Its almost 8hrs I got a stuck with the @AfterThrowing aspect problem,
    my enviornment is apsectj 1.5.3, asm 2.2, hibernate 3.2.0 and spring 2.0

    This is my configuration file

    <bean id="throwsAdvice" class="com.dpwn.newops.server.framework.intercepto r.exception.NewOpsAfterThrowsAdvise" />

    <!-- Enable aspects -->
    <aop:aspectj-autoproxy/>

    <aop:config>
    <aop:aspect id="afterThrowing" ref="throwsAdvice">
    <aopointcut id="executionOfMethods"
    expression="execution(* com..*.*(..))"/>
    <aop:after-throwing
    pointcut-ref="executionOfMethods"
    throwing="ex"
    method="afterThrowing"/>
    </aop:aspect>
    </aop:config>
    and aspect code is

    @Aspect
    public class NewOpsAfterThrowsAdvise {

    @AfterThrowing(pointcut="execution(* com.*.*(..))", throwing="ex")
    public void afterThrowing(Throwable ex) {
    ............
    }
    }

    The problem is that when i try to initialize the spring context, i get the following exception

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean wit
    h name 'org.springframework.aop.aspectj.AspectJPointcutAd visor': Cannot create i
    nner bean '(inner bean)' while setting bean property 'advice'; nested exception
    is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean
    with name '(inner bean)': Invocation of init method failed; nested exception is
    java.lang.IllegalStateException: Throwing argument name 'ex' was not bound in ad
    vice arguments
    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creati
    ng bean with name '(inner bean)': Invocation of init method failed; nested excep
    tion is java.lang.IllegalStateException: Throwing argument name 'ex' was not bou
    nd in advice arguments
    Caused by: java.lang.IllegalStateException: Throwing argument name 'ex' was not
    bound in advice arguments
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.bindExplicitArg
    uments(AbstractAspectJAdvice.java:412)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.bindArgumentsBy
    Name(AbstractAspectJAdvice.java:375)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.calculateArgume
    ntBindings(AbstractAspectJAdvice.java:331)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.afterProperties
    Set(AbstractAspectJAdvice.java:297)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBean
    Factory.invokeInitMethods(AbstractAutowireCapableB eanFactory.java:1062)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBean
    Factory.initializeBean(AbstractAutowireCapableBean Factory.java:1029)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBean
    Factory.createBean(AbstractAutowireCapableBeanFact ory.java:420)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver
    .resolveInnerBeanDefinition(BeanDefinitionValueRes olver.java:198)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver
    .resolveValueIfNecessary(BeanDefinitionValueResolv er.java:116)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBean
    Factory.applyPropertyValues(AbstractAutowireCapabl eBeanFactory.java:955)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBean
    Factory.populateBean(AbstractAutowireCapableBeanFa ctory.java:729)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBean
    Factory.createBean(AbstractAutowireCapableBeanFact ory.java:416)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getOb
    ject(AbstractBeanFactory.java:245)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistr
    y.getSingleton(DefaultSingletonBeanRegistry.java:1 41)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean
    (AbstractBeanFactory.java:242)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean
    (AbstractBeanFactory.java:156)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.
    preInstantiateSingletons(DefaultListableBeanFactor y.java:290)
    at org.springframework.context.support.AbstractApplic ationContext.refres
    h(AbstractApplicationContext.java:348)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<i
    nit>(ClassPathXmlApplicationContext.java:92)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<i
    nit>(ClassPathXmlApplicationContext.java:77)
    at com.dpwn.newops.integration.integrationtest.Server IntegrationApp.init
    (ServerIntegrationApp.java:50)
    at com.dpwn.newops.integration.integrationtest.Server IntegrationApp.main
    (ServerIntegrationApp.java:34)
    Exception in thread "main" java.lang.NullPointerException
    at com.dpwn.newops.integration.integrationtest.Server IntegrationApp.init
    (ServerIntegrationApp.java:61)
    at com.dpwn.newops.integration.integrationtest.Server IntegrationApp.main
    (ServerIntegrationApp.java:34)

    I found similar queries in the forum and updated my Asm jar to 2.2 but still i get this exception.

    any thoughts what Im doing wrong?

    Thanks,
    Ravi

  • #2
    Spring Gurus,
    any pointers for my problem?

    Comment


    • #3
      You are trying to use both declarative (using aop aspectj and annotation based aspectj <aop:aspectj-autoproxy/>. Remove one of the 2 don't mix.

      I personally favor the declarative style, Annotations I still need to get used to .

      Remove annotations from your class
      Code:
      public class NewOpsAfterThrowsAdvise {
          public void afterThrowing(Throwable ex) { 
             //Do stuff
          }
      }
      Remove the <aop:aspectj-autoproxy/> from your config and I also think your aopointcut is in the wrong place, change your aop config

      Code:
      <aop:config>
          <aop:pointcut id="executionOfMethods" expression="execution(* com..*.*(..))"/>
          <aop:aspect id="afterThrowing" ref="throwsAdvice">
              <aop:after-throwing pointcut-ref="executionOfMethods" throwing="ex" method="afterThrowing"/>
          </aop:aspect>
      </aop:config>
      Last edited by Marten Deinum; Dec 12th, 2006, 10:35 AM. Reason: Removed some typos

      Comment


      • #4
        tried that, but hard luck!

        Comment


        • #5
          what is happening now and can you post your new configuration also?

          Comment


          • #6
            Hi,
            here's is my config file

            <?xml version="1.0" encoding="UTF-8"?>
            <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:aop="http://www.springframework.org/schema/aop"
            xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.0.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-2.0.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">


            <bean id="throwsAdvice" class="com.dpwn.newops.server.framework.intercepto r.exception.NewOpsAfterThrowsAdvise" />

            <aop:config>
            <aopointcut id="afterThrowingID" expression="execution(* com..*.*(..))"/>
            <aop:aspect id="afterThrowing" ref="throwsAdvice">
            <aop:after-throwing pointcut-ref="afterThrowingID" throwing="ex" method="afterThrowing"/>
            </aop:aspect>
            </aop:config>

            </beans>


            and this is my Advise

            public class NewOpsAfterThrowsAdvise {
            public void afterThrowing(Throwable ex) {
            List <String>params = new ArrayList<String>();

            // Do something will all arguments
            System.out.print("Exception caught in the interceptor...");
            System.out.println(ex.getClass().getSimpleName());
            }
            }

            Exactly the same exception still repeats.

            Also i upgraded Asm from 2.2 to asm 2.2.2
            and using cglib-nodep 2.1_3

            Let me know if need other information?

            Comment


            • #7
              Also is there a way to find which version of the ASM is being used by spring at runtime? just to be sure spring is using ASM 2.2.2?

              Comment


              • #8
                You still have the same exception or is it another one?

                Also is there a way to find which version of the ASM is being used by spring at runtime? just to be sure spring is using ASM 2.2.2?
                Hmm not that I know of, just make sure there are no other versions of the ASM jar in your classpath.

                Comment


                • #9
                  it is the same exception!

                  Im using maven2 to generate a assembled jar, Im explicitly removing the older version (that comes as a part of hibernate) and included the newer version of ASM.

                  Comment


                  • #10
                    Hi,
                    I am also having the same issue. Were you able to solve the problem ?

                    Comment


                    • #11
                      unfortunately not, still living with the same problem...

                      Comment


                      • #12
                        Even my vacation got over but this problems don't seems to going away!

                        This is a problem seems to be a maven 2 configuration as I could have my code working when executed from eclipse!


                        Also i was debugging (on the complied code by Maven, complied code through eclipse works fine) using Spring code and here's my findings.

                        This is my Advise Code
                        public class NewOpsAfterThrowsAdvise {

                        public void afterThrowing(Throwable ex) {
                        List <String>params = new ArrayList<String>();

                        // Do something will all arguments
                        System.out.print("Exception caught in the interceptor...");
                        System.out.println(ex.getClass().getSimpleName());

                        //Log the exception.

                        //unwrap the exception
                        if(ex instanceof RuntimeException) {
                        String issueCode;
                        if(ex instanceof NewOpsRuntimeException){
                        issueCode = ((NewOpsRuntimeException)ex).getIssues().get(0).ge tCode();
                        }else{
                        issueCode = ex.getMessage();
                        }
                        if (ex.getCause() == null) {
                        params.add( ex.getClass().getSimpleName());
                        } else {
                        while (ex.getCause() != null) {
                        ex = ex.getCause();
                        }
                        params.add(ex.getMessage());
                        params.add(ex.getCause().getClass().getSimpleName( ));
                        }
                        throw new NewOpsRuntimeException(issueCode, params,ex);
                        }
                        }
                        • In the class LocalVariableTableParameterNameDiscoverer.java

                          private ParameterNameDiscoveringVisitor visitMethod(Method method) throws IOException {
                          ClassReader reader = new ClassReader(method.getDeclaringClass().getName());
                          FindMethodParamNamesClassVisitor classVisitor = new FindMethodParamNamesClassVisitor(method);
                          reader.accept(classVisitor,false);
                          return classVisitor;
                          }

                          The Class visitor that is returned has parameterNames as "issueCode" which is a local variable in my advise code, but the correct value for parameters should be "ex"
                          Any thoughts what's going wrong??

                          tried a tricky thing, In the maven generated jar, i replaced my advise class file with eclipse compiled advise class file
                          and it worked! thus driving to point my figures towards my Pom file......

                          for Maven to compile AOP, Do i need to have any special plug-ins installed?

                          Regards,
                          Ravi

                        Comment


                        • #13
                          Originally posted by rnallakukkala View Post
                          Even my vacation got over but this problems don't seems to going away!

                          This is a problem seems to be a maven 2 configuration as I could have my code working when executed from eclipse!


                          Also i was debugging (on the complied code by Maven, complied code through eclipse works fine) using Spring code and here's my findings.

                          This is my Advise Code
                          public class NewOpsAfterThrowsAdvise {

                          public void afterThrowing(Throwable ex) {
                          List <String>params = new ArrayList<String>();

                          // Do something will all arguments
                          System.out.print("Exception caught in the interceptor...");
                          System.out.println(ex.getClass().getSimpleName());

                          //Log the exception.

                          //unwrap the exception
                          if(ex instanceof RuntimeException) {
                          String issueCode;
                          if(ex instanceof NewOpsRuntimeException){
                          issueCode = ((NewOpsRuntimeException)ex).getIssues().get(0).ge tCode();
                          }else{
                          issueCode = ex.getMessage();
                          }
                          if (ex.getCause() == null) {
                          params.add( ex.getClass().getSimpleName());
                          } else {
                          while (ex.getCause() != null) {
                          ex = ex.getCause();
                          }
                          params.add(ex.getMessage());
                          params.add(ex.getCause().getClass().getSimpleName( ));
                          }
                          throw new NewOpsRuntimeException(issueCode, params,ex);
                          }
                          }
                          • In the class LocalVariableTableParameterNameDiscoverer.java

                            private ParameterNameDiscoveringVisitor visitMethod(Method method) throws IOException {
                            ClassReader reader = new ClassReader(method.getDeclaringClass().getName());
                            FindMethodParamNamesClassVisitor classVisitor = new FindMethodParamNamesClassVisitor(method);
                            reader.accept(classVisitor,false);
                            return classVisitor;
                            }

                            The Class visitor that is returned has parameterNames as "issueCode" which is a local variable in my advise code, but the correct value for parameters should be "ex"
                            Any thoughts what's going wrong??

                            tried a tricky thing, In the maven generated jar, i replaced my advise class file with eclipse compiled advise class file
                            and it worked! thus driving to point my figures towards my Pom file......

                            for Maven to compile AOP, Do i need to have any special plug-ins installed?

                            Regards,
                            Ravi
                          If I remove all the local variables from my advise method
                          then my advise works even when compiled through maven.

                          But haven't understood the relation between Maven compile code and Local variables in advise method.
                          any thoughts what's the missing link?


                          further debugging the spring code in LocalVariableTableParameterNameDiscoverer.java for the method

                          public void visitLocalVariable(String name, String description, String signature, Label start, Label end, int index) {
                          this.hasLVTInfo = true;
                          if (!this.isStatic) {
                          index--;
                          }
                          if (index >= 0 && (this.parameterNames.size() < this.numParameters)) {
                          this.parameterNames.add(name);
                          }
                          }

                          this method is invoked multiple times, If advise code compiled through Maven then "name" attribute of the method is invoked with the following values sequentially
                          • issueCode (local variable name)
                          • ex (parameter binding)

                          the same if advise code is compiled through my eclipse then the "name" attribute receives the following values sequentially
                          • this
                          • ex
                          • issueCode

                          My question is, why does the order of the method invocation change when compiled through Eclipse or Maven?
                          any pointers would be great help!!

                          Comment


                          • #14
                            any helping hands for my problem?

                            Comment


                            • #15
                              I'm I the only one stuck with this stupid problem!?

                              Comment

                              Working...
                              X