Announcement Announcement Module
Collapse
No announcement yet.
After-returning an array problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • After-returning an array problem

    I am trying to write an aspect that will do some logging whenever one of my service methods returns an instance of my domain object, or an array of my domain object. I was able to successfully intercept my domain object with no problem, but my interceptor that intercepts arrays does not seem to function. This is the code I'm using:

    Code:
    <aop:config>
       <aop:aspect id="loggingAspect" ref="logger">
       <aop:after-returning
          pointcut="execution(com.mycompany.DomainObject com.mycompany.services.MyService.*(..)"
          returning="domainObject"
          method="writeToAuditLog"/>
       <aop:after-returning
          pointcut="execution(com.mycompany.DomainObject[] com.mycompany.services.MyService.*(..)"
          returning="domainObjects"
          method="writeArrayToAuditLog"/>
       </aop:aspect>
    </aop:config>
    From what I can tell from the debugger, it looks like the second interceptor is not intercepting my method at all. Is there something wrong with my pointcut? I am currently limited to Java 1.4; otherwise I would try it with annotations.
    Last edited by jcshiff; Mar 20th, 2007, 02:25 PM.

  • #2
    I notice that you are missing closing ")" in each pointcut (however, since the first advice is working, that may not explain the problem you are facing).

    What does your advice method look like? Can you isolate the problem in a small set of classes and configuration?

    -Ramnivas

    Comment


    • #3
      Thank you for your fast reply. The missing ")" is just a typo. I made a much simpler project that just contains the beans mentioned in my example, and the problem persists. I would zip it all up and post it here, but my workstation is not connected to the Internet. After more thorough tracing with the debugger, the problem seems to be that AspectJExpressionPointcut.matches(Method, Class, boolean) always returns false when the pointcut is defined to intercept methods that return arrays. I think that I am using the correct syntax for an array based on the AspectJ programming guide.

      I am using Spring 2.0.1, but in the changelog for 2.0.3, there is a line: AspectJExpressionPointcut ignores target classes not accepted by PointcutExpression matching (such as arrays)
      I'm not sure what that means, but it sounds like upgrading would not help?

      More disturbingly, I discovered that AspectJAfterReturningAdvice.shouldInvokeOnReturnVa lueOf will throw a NullPointerException if the value returned by my working method is null. This leads me to consider switching to a pointcut that intercepts regardless of return value, which I have tested and found to work properly.

      Comment


      • #4
        Thanks for reporting back. It indeed looks like a bug. Please file a JIRA issue so that this can be fixed in a future version.

        -Ramnivas

        Comment

        Working...
        X