Challenge - 5 Problems
Master of @Around Advice
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this @Around advice code?
Consider this Spring Boot @Around advice that logs method execution time. What will be printed when the advised method completes successfully?
Spring Boot
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.springframework.stereotype.Component; @Aspect @Component public class TimingAspect { @Around("execution(* com.example.service.*.*(..))") public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { long start = System.currentTimeMillis(); Object proceed = joinPoint.proceed(); long duration = System.currentTimeMillis() - start; System.out.println("Execution time: " + duration + " ms"); return proceed; } }
Attempts:
2 left
💡 Hint
Remember that joinPoint.proceed() runs the original method and returns its result.
✗ Incorrect
The @Around advice calls proceed() to execute the original method, measures time before and after, prints the duration, and returns the original method's result.
📝 Syntax
intermediate2:00remaining
Which option correctly uses @Around advice to modify the returned value?
You want to intercept a method and multiply its integer return value by 10 before returning it. Which @Around advice code snippet is correct?
Attempts:
2 left
💡 Hint
Check method signature and casting carefully.
✗ Incorrect
Option B correctly declares the method to throw Throwable, casts proceed() result to int, and returns the multiplied value as Object.
🔧 Debug
advanced2:00remaining
Why does this @Around advice cause a StackOverflowError?
This advice is intended to log method calls but causes a StackOverflowError at runtime. What is the cause?
Spring Boot
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.springframework.stereotype.Component; @Aspect @Component public class LoggingAspect { @Around("execution(* com.example.service.*.*(..))") public Object log(ProceedingJoinPoint pjp) throws Throwable { System.out.println("Before method"); Object result = log(pjp); // recursive call instead of proceed() System.out.println("After method"); return result; } }
Attempts:
2 left
💡 Hint
Look at the method call inside the advice method.
✗ Incorrect
The advice method calls itself recursively instead of calling pjp.proceed(), leading to infinite recursion and StackOverflowError.
❓ state_output
advanced2:00remaining
What is the value of 'count' after this @Around advice runs three times?
This advice counts how many times methods in the service package are called. What is the value of 'count' after three method calls?
Spring Boot
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.springframework.stereotype.Component; @Aspect @Component public class CounterAspect { private int count = 0; @Around("execution(* com.example.service.*.*(..))") public Object countCalls(ProceedingJoinPoint pjp) throws Throwable { count++; return pjp.proceed(); } public int getCount() { return count; } }
Attempts:
2 left
💡 Hint
Each method call increments count by one.
✗ Incorrect
The advice increments 'count' every time a matched method is called. After three calls, count is 3.
🧠 Conceptual
expert2:00remaining
Which statement about @Around advice full control is TRUE?
Select the true statement about the capabilities of @Around advice in Spring AOP.
Attempts:
2 left
💡 Hint
Think about what full control means in this context.
✗ Incorrect
@Around advice wraps the method call, allowing you to change arguments, decide whether to call the method, and modify the return value.