Page 3 of 3 FirstFirst 123
Results 21 to 28 of 28

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

  1. #21
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    I am quite interested in your small Maven project. AFAIK, local variables should have no roles to play (good or bad!).

    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  2. #22

    Default Sample Maven Project

    Attached is a simple maven project that reproduces the error. 2 classes, the aspect, and a test class to load the app context. Maybe I am just missing something obvious, but the behavior sure seems weird. If anybody has any thoughts, let me know
    Attached Files Attached Files

  3. #23
    Join Date
    Aug 2005
    Posts
    4

    Default Also seeing behavior with after-returning advice

    I am also seeing this behavior. It occurs with both after-returning and after-throwing advice. If I build with Eclipse, everything works as it should. If I build with javac ( debug enabled ) I see the exception. I've tried switching to Load Time Weaving, forcing CGLIB proxies, etc. but nothing seems to work. I'm reluctant to move all of our automated builds to the Eclipse JDT compiler. Has there been any progress on this issue? Does anyone have another workaround?

    My environment:
    Using xml aop:config ( no mixing with annotations )
    Spring 2.0, ASM 2.2.2, cglib-nodep-2.1.3
    MyEclipse 5.1GA
    Eclipse 1.5.2v20061111
    jdk 1.5.0_07

    Thanks,
    Mark

  4. #24

    Default Created a JIRA issue

    I have created a JIRA issue to track this... We'll see what reply I get.

    SPR-3307

  5. #25
    Join Date
    Aug 2005
    Posts
    4

    Default My workaround

    So here's what I discovered. If I remove the "debug" flag from javac everything works at runtime ( no exception ).

    However, we use cobertura for test coverage analysis which requires that the class files to be instrumented be compiled with debug enabled.

    So instead of runtime weaving I tried compile time weaving ( i.e. using the AspectJ compiler ajc ). This is easy to setup and it solves the problem. I'm able to compile with debug enabled and I do not get the exception.

    Here's a link to a post which specifies how to setup ajc in ant.

    http://forum.springframework.org/sho...op.xml+weaving

    Hope this helps,
    Mark

  6. #26

    Default

    Quote Originally Posted by jkoppenhofer View Post
    I have created a JIRA issue to track this... We'll see what reply I get.

    SPR-3307
    Looks like this fix will be part of Spring AOP 2.0.4 release!!!! Thank You

  7. #27
    Join Date
    Dec 2008
    Posts
    1

    Default java.lang.IllegalStateException: Throwing argument name 'ex' was not bound in advice

    I started getting the above exception after altering the following class in my app:

    Code:
    @Aspect
    @Order(1)
    public class LoggingExceptionAdvice {
          private static Logger logger = Logger.getLogger(LoggingExceptionAdvice.class);
          @AfterThrowing(pointcut="za.co.metcapri.common.aop.SystemPointCuts.inCapri()",throwing="ex")
          public void afterThrowing(Exception ex) throws Throwable {
                if (!(ex instanceof BusinessException)){
    //                StringWriter stringWriter = new StringWriter();
    //                PrintWriter printWriter = new PrintWriter(stringWriter, true);
    //                ex.printStackTrace(printWriter);
    //                printWriter.close();
    //                logger.error(stringWriter.toString());
                      logger.error(ex);
                }
          }
    }
    The commented out code above is what caused this exception.

    When I reverted back to just logging the exception, all was well again.

    The problem is that logger.error(ex) only logs the first line and not the full stack trace.

    Any ideas why the above code causes Advice configuration failure?

  8. #28
    Join Date
    Jun 2009
    Posts
    24

    Default

    I tried the Spring example http://static.springsource.org/sprin.../html/aop.html

    and here is my code

    public class AfterThrowingExample {


    public void doRecoveryActions() {
    System.out.println(" AfterThrowingExample ");
    }


    }

    applicationContext.xml

    <bean id="afterThrowing" class="cs.comp.aop.AfterThrowingExample"/>


    <aop:config>
    <aop:aspect id="executionOfMethods" ref="afterThrowing">
    <aopointcut id="afterThrowingPointCut"
    expression="execution(* cs.comp.service.GeekTransactionService.addRecords* (..))" />
    <aop:after-throwing
    pointcut-ref="geekServicePointCut"
    method="doRecoveryActions"/>
    </aop:aspect>
    </aop:config>


    And it works fine for me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •