Bird
0
0

Why does this @Around advice cause a stack overflow?

medium📝 Troubleshoot Q7 of 15
Spring Boot - Aspect-Oriented Programming
Why does this @Around advice cause a stack overflow?
@Around("execution(* com.example.*.*(..))")
public Object logAround(ProceedingJoinPoint pjp) throws Throwable {
    System.out.println("Before method");
    Object result = logAround(pjp);
    System.out.println("After method");
    return result;
}
AIncorrect pointcut expression
BRecursive call to advice method instead of proceeding
CMissing @Before annotation
DAdvice method must not return a value
Step-by-Step Solution
Solution:
  1. Step 1: Identify recursive call

    The advice calls itself logAround(pjp) instead of pjp.proceed(), causing infinite recursion.
  2. Step 2: Confirm other options are invalid

    Missing @Before is unrelated, pointcut is valid, and advice can return values.
  3. Final Answer:

    Recursive call to advice method instead of proceeding -> Option B
  4. Quick Check:

    Use pjp.proceed() to continue method execution [OK]
Quick Trick: Call pjp.proceed() inside @Around advice to avoid recursion [OK]
Common Mistakes:
  • Calling advice method recursively
  • Forgetting to call pjp.proceed()
  • Misunderstanding @Around advice structure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes