Bird
0
0

What is wrong with this AOP advice for measuring execution time?

medium📝 Troubleshoot Q14 of 15
Spring Boot - Aspect-Oriented Programming
What is wrong with this AOP advice for measuring execution time?
@Around("execution(* com.example..*(..))")
public void measure(ProceedingJoinPoint pjp) throws Throwable {
  long start = System.currentTimeMillis();
  pjp.proceed();
  long end = System.currentTimeMillis();
  System.out.println("Time: " + (end - start));
}
AThe pointcut expression is invalid
BThe method should return Object, not void
CSystem.currentTimeMillis() cannot be used for timing
DProceedingJoinPoint cannot be used in @Around advice
Step-by-Step Solution
Solution:
  1. Step 1: Check method signature for @Around advice

    @Around advice must return the result of pjp.proceed() to maintain method behavior.
  2. Step 2: Identify missing return statement

    Method returns void but should return Object from pjp.proceed().
  3. Final Answer:

    The method should return Object, not void -> Option B
  4. Quick Check:

    @Around advice must return method result [OK]
Quick Trick: @Around methods must return Object from proceed() [OK]
Common Mistakes:
  • Forgetting to return pjp.proceed() result
  • Thinking pointcut syntax is wrong
  • Believing System.currentTimeMillis() is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes