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

  • #16
    Same thing here

    Exact same situation here...
    • Compiling in Eclipse works
    • Compiling using maven2 fails
    • Replacing the Advice class file that Maven built with the one Eclipse built allows the thing to work.
    • Removing all local variables also allows it to work when built by Maven2

    My situation is exactly the same as the OP, and I can't think of anything else to post, so if you want more details, just look above in this post

    Anybody have any ideas?

    Comment


    • #17
      I think I know what is going on...

      Compile your aspects using either -g or -g:vars flag. When you use any context (this, target, argument, thrown exception etc.), Spring's AOP mechanism needs to figure out the advice argument names. Without -g or -g:vars, javac simply removes all method argument names (and local variables).

      Please try it and report your experience.

      -Ramnivas

      Comment


      • #18
        I tried that already

        I've already tried that I've forked the maven2 compiler to assure me that I am using an up to date javac. I have tried using -g and -g:var flags as seen in the config below... Still no go. Technically you should not need to set the debug flag anyway because it is set by default as part of the maven-compiler-plugin.

        ramnivas: Did you actually get this working? or did you just abandon it, or remove all local variables?

        Code:
              <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                  <fork>true</fork>
                  <source>1.5</source>
                  <target>1.5</target>
                  <executable>C:\Javatool\java\jdk1.6.0\bin\javac</executable>
                  <compilerArgument>-g</compilerArgument>
                </configuration>
              </plugin>

        Comment


        • #19
          I haven't used Spring-AspectJ-AOP/Maven combination (used Spring/AspectJ/Maven combination, but that is a different story). I have, however, used Spring-AspectJ-AOP/Ant combination. I have seen exactly the same problem as described (and there are many other threads with the same problem and solution). In each cases, adding -g/-g:vars solved the problem.

          I notice that you are using Java6 compiler (granted, you are using -source 5). I do wonder if that is somehow playing a role. Can you try using Java5 compiler? There are known issues with using AspectJ along with Java 6.

          -Ramnivas

          Comment


          • #20
            Now that is weird

            Still no luck with using the jdk5 compiler with -g

            HOWEVER, I did make a very interesting discovery. I seem to be able to have local variables as long as they are not of type "Object". For example...

            Code:
            Object arg = call.getArgs()[paramIndex];
            ... Just does not work... All my other locals seem to be fine?!?!?!?! Heck, even...

            Code:
            Object arg=null
            ... makes it fail I think I can work around the issue now, but this certainly is disturbing. If I have time I will do a very basic maven2 project that duplicates the issue, and post it for others to play with. If anyone else has experienced such a behavior, please let me know.

            Comment


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

              -Ramnivas

              Comment


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

                Comment


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

                  Comment


                  • #24
                    Created a JIRA issue

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

                    SPR-3307

                    Comment


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

                      Comment


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

                        Comment


                        • #27
                          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?

                          Comment


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

                            Comment

                            Working...
                            X