Announcement Announcement Module
Collapse
No announcement yet.
How to make MethodBeforeAdvice completely exit? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to make MethodBeforeAdvice completely exit?

    Hi,

    Here is my situation.

    I want a particular set of methods on a variety of objects to first perform a check. If that check is passed, these methods should execute normally. If the check fails, method execution should not commence at all and we should just return to the caller.

    This seems like a prime candidate for BeforeAdvice/MethodBeforeAdvice, except for one thing -- after execution of BeforeAdvice, the advised method would execute regardless of whether or not the check is passed.

    I suppose I could have the BeforeAdvice throw an exception if the check fails, but this seems kind of like a hack to me. Plus, I'd rather not throw exceptions needlessly since they consume more stack space than what would be required if I could just get the MethodBeforeAdvice to cause the exiting of the advised method entirely.

  • #2
    Why not just use an around advise?

    Comment


    • #3
      yeah, of course.

      Use MethodInterceptor and do the check inside there. IF the check fails, just return null instead of returning the return value given by invocation.proceed().

      Thanks for pointing that out.

      Comment

      Working...
      X